问题描述:

I'm having a problem with Python 2.6 on windows.

Whether I try:

fileobj=open("nonexistent.txt","w")

or

fil=os.open("nonexistent.txt", os.O_CREAT)

fileobj=file(fil)

I get an error:

IOError: [Errno 2] No such file or directory: 'nonexistent.txt'

What may be the problem?

网友答案:

You will not be able to read the file if it does not exist, however, you should be able to write to it. Does the code below return the same error?

f=open("nonexistent.txt","w")
f.write('Test')
f.close()
网友答案:

At seems like a permission problem. Try opening the file somewhere else or run the python as an Administrator.

相关阅读:
Top