Mehedi Hasan
Mehedi Hasan

Reputation: 3

wrong Error Name 'file' can be undefined in python pycharm

enter image description here Why it's showing an Error

try: file = open("main.py") age = int(input("Enter age: ")) except (ValueError, ZeroDivisionError): print("Enter valid Number") else: print("How are you?") finally: file.close()

Upvotes: 0

Views: 294

Answers (1)

yoyopi768 yoyopi768
yoyopi768 yoyopi768

Reputation: 161

Instead of open, try with open, and remove the finally statement with the close. This will automatically close it.

Upvotes: 2

Related Questions