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 2,534 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,460 points

Related Questions In Python

+2 votes
9 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 324,358 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,770 points
1,098 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,840 points
5,798 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 4,466 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,460 points
3,577 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,460 points
24,358 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP