0

I'm trying to open a file using this code but it is again and again showing the error: NameError: name "practice" is not defined where "practice" is the name of the file which I'm trying to open. "practice.txt" (the file that im trying to open) is present in the same directory in which my python program has been created.

import os
name = input("Enter the name of the file : ") 
if(os.path.exist(name)==True):
    fopen = open(name,'w')
    line = fopen.readline()
    while(line != ""):
        print(line)
        line=fopen.readline()
    fopen.close()
else:
    print("file does not exist!!!")
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Anant Vikram Singh
  • 109
  • 1
  • 3
  • 14

1 Answers1

0

This is because you must specify the PATH of the file as well as the filename.

I.E. open("Files/images/Image1.png", "MODE")

EgMusic
  • 136
  • 17