Question: #program name: workWithFiles2.py #program description: here we are checking whether two files exist and if they exists print out the contents in it and perform
#program name: workWithFiles2.py
#program description: here we are checking whether two files exist and if they exists print out the contents in it and perform
#name :bhumika patel
if(path.exists('cpt180Stuff2/pets/dogs/dognames.txt') and path.exists('cpt180Stuff2/pets/cats/catnames.txt')):
f1= open('pets/dogs/dognames.txt','r')
print(f1.read())
f1.close()
print(" ")
f2= open('pets/cats/catnames.txt','r')
print(f2.read())
f2.close()
print(' ')
f2= open('pets/cats/catnames.txt','a')
f2.write(' ')
f2.write('Mortimer')
f2.write(' ')
f2.write('Tigger')
f2.close()
f2= open('pets/cats/catnames.txt','r')
print(f2.read())
f2.close()
else:
print("Unable to access one or more files")
This is my code and I am getting error saying as shown below. How can I correct that error ?
NameError: name 'path' is not defined
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
