I have a function:
def loadFile(file): path = script_dir + file #script_dir has the form '/home/username/blah/blah/' and file has the form 'asdf/foo.txt' temp = open(path,'w') temp.close() with open(path) as f: return f.read().replace('\n', '') When I run print(loadFile('asdf/asdf.txt')) in python3, I get the error:
FileNotFoundError: [Errno 2] No such file or directory: '/home/username/blah/blah/asdf/asdf.txt' Why is this happening? I am very confused. everywhere I look it says that 'w' will create the file, why isn't it.
Note1: I run Zorin OS Education Lite (sorry I can't provide you with more universal terminology).
Note2: I have an NTFS partition mounted at /home/username/blah/
没有评论:
发表评论