I got expected an indented block error

0 votes
from pynput.keyboard import Key, Listener
import logging
log_dir = r"C:/users/rajesh/desktop/"
logging.basicConfig(filename = (log_dir + "keyLog.txt"), level=logging.DEBUG, format='%(asctime)s: %(message)s')
def on_press(key):
logging.info(str(key))
with Listener(on_press=on_press) as listener:
listener.join()
Jun 16, 2020 in Python by anonymous
• 120 points

edited Jun 16, 2020 by MD 1,478 views

Hi, @Tejas,

Could you please post your error logs whatever error statement you are facing? 

1 answer to this question.

0 votes

Hi,

You used one function in your code, but you didn't indent your code inside this function properly. This may be the reason.

from pynput.keyboard import Key, Listener
import logging
log_dir = r"C:/users/rajesh/desktop/"
logging.basicConfig(filename = (log_dir + "keyLog.txt"), level=logging.DEBUG, format='%(asctime)s: %(message)s')
def on_press(key):
    logging.info(str(key))
    with Listener(on_press=on_press) as listener:
        listener.join()
answered Jun 16, 2020 by MD
• 95,340 points

Related Questions In Python

+1 vote
3 answers

Python error "IndentationError: expected an indented block"

Python requires its code to be indented ...READ MORE

answered Jun 17, 2019 in Python by Varun

edited Jun 17, 2019 220,740 views
0 votes
1 answer

I've been trying to run this code, but the error says "Expected an indented block" for the line, " word_as_list[index] = guess."

Hi, @Paradox, The error message IndentationError: expected an indented ...READ MORE

answered Nov 21, 2020 in Python by anonymous
• 65,850 points
340 views
0 votes
1 answer

IndentationError: expected an indented block

Hello @ nishit, Indentation means the space from margin to ...READ MORE

answered Aug 10, 2020 in Python by Niroj
• 82,680 points
3,979 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 2,758 views
0 votes
1 answer
0 votes
1 answer

I was written the python program, am getting error message "IndentationError: expected an indented block"

Hi@Thiyagarajan, You have one else block in your ...READ MORE

answered May 27, 2020 in Python by MD
• 95,340 points
2,562 views
0 votes
1 answer

I am trying to install PIL module But I end up with an error :

Hi@Nishant, You can use PILLOW instead of PIL. $ ...READ MORE

answered Apr 6, 2020 in Python by MD
• 95,340 points
15,734 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP