python 2.5 - f=open('a_file.txt','w') gives [Errno 2]

Hrvoje Niksic hniksic at xemacs.org
Mon Dec 3 10:40:02 EST 2007


dirkheld <dirkheld at gmail.com> writes:

> I don't have a file called 'a_file.txt'
> I want to create that file and write some data to it.

How exactly are you starting the Python interpreter?  "No such file or
directory" on file creation can happen when you try to create a file
in a directory that has ceased to exist:

$ mkdir x
$ cd x
$ rm -rf ~/x
$ python
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('foo', 'w')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'foo'



More information about the Python-list mailing list