473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

Hi,

I upgraded my system from tiger to leopard. With leopard came a new
version of python 2.5

Now I trying to run some python code that previously worked on tiger
(which included an older version of python).

This is the error I'm receiving :

Traceback (most recent call last):
File "test.py", line 18, in print_total
f=open('a_file.txt','w')
IOError: [Errno 2] No such file or directory: 'a_file.txt'
Is this a bug in python? This code worked on my old system
Dec 3 '07 #1
8 2704
dirkheld wrote:
Hi,

I upgraded my system from tiger to leopard. With leopard came a new
version of python 2.5

Now I trying to run some python code that previously worked on tiger
(which included an older version of python).

This is the error I'm receiving :

Traceback (most recent call last):
File "test.py", line 18, in print_total
f=open('a_file.txt','w')
IOError: [Errno 2] No such file or directory: 'a_file.txt'
Is this a bug in python? This code worked on my old system
The obvious question is: do you have 'a_file.txt' on your new system? There
are many happy python programmers on leopard, and this is one heck of a
basic functionality - I really doubt it's broken in such obvious way (if
any at all).

Diez
Dec 3 '07 #2
On Dec 3, 7:47 am, dirkheld <dirkh...@gmail.comwrote:
IOError: [Errno 2] No such file or directory: 'a_file.txt'
I sometimes see that error on Linux when trying to run a script with
DOS line endings. Is it an imported file? I don't know Macs, but start
by making sure both your script and the file have Mac line endings?

rick
Dec 3 '07 #3
On 3 dec, 14:54, "Diez B. Roggisch" <de...@nospam.web.dewrote:
dirkheld wrote:
Hi,
I upgraded my system from tiger to leopard. With leopard came a new
version of python 2.5
Now I trying to run some python code that previously worked on tiger
(which included an older version of python).
This is the error I'm receiving :
Traceback (most recent call last):
File "test.py", line 18, in print_total
f=open('a_file.txt','w')
IOError: [Errno 2] No such file or directory: 'a_file.txt'
Is this a bug in python? This code worked on my old system

The obvious question is: do you have 'a_file.txt' on your new system? There
are many happy python programmers on leopard, and this is one heck of a
basic functionality - I really doubt it's broken in such obvious way (if
any at all).

Diez
I don't have a file called 'a_file.txt'
I want to create that file and write some data to it. (http://
docs.python.org/tut/node9.html#SECTION009200000000000000000)
The strange thing is that it worked under tiger with an older vesion
of python without any problem....
Dec 3 '07 #4
dirkheld wrote:
On 3 dec, 14:54, "Diez B. Roggisch" <de...@nospam.web.dewrote:
>dirkheld wrote:
Hi,
I upgraded my system from tiger to leopard. With leopard came a new
version of python 2.5
Now I trying to run some python code that previously worked on tiger
(which included an older version of python).
This is the error I'm receiving :
Traceback (most recent call last):
File "test.py", line 18, in print_total
f=open('a_file.txt','w')
IOError: [Errno 2] No such file or directory: 'a_file.txt'
Is this a bug in python? This code worked on my old system

The obvious question is: do you have 'a_file.txt' on your new system?
There are many happy python programmers on leopard, and this is one heck
of a basic functionality - I really doubt it's broken in such obvious way
(if any at all).

Diez

I don't have a file called 'a_file.txt'
I want to create that file and write some data to it. (http://
docs.python.org/tut/node9.html#SECTION009200000000000000000)
The strange thing is that it worked under tiger with an older vesion
of python without any problem....
Oh sorry, my bad. I didn't see the mode flag. Do you by any chance happen to
not have the right to create files in the directory you are? What happens
if you use it in /tmp for example?

Still, I hold up to my reasoning: writing files is so essential in python,
and certainly not subject to great - if any - change (after all, it's just
calling the underlying OS functions) that I doubt it is broken.

Diez
Dec 3 '07 #5
dirkheld <di******@gmail.comwrites:
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'
Dec 3 '07 #6
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:
Damn...now it's time to be ashamed. Because of my new installation of
leopard I used another computername. So the path were I wanted to
write to didn't exist any more.

Previous : /users/dirkheld/programming/python/....
Now : /users/dirk/programming/python/...

Sorry for keeping you guys busy with such a mistake ;)
Dec 4 '07 #7
dirkheld a écrit :
>>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:


Damn...now it's time to be ashamed. Because of my new installation of
leopard I used another computername. So the path were I wanted to
write to didn't exist any more.

Previous : /users/dirkheld/programming/python/....
Now : /users/dirk/programming/python/...
which should remind everybody that hard-coding a path is a bad idea !-)
Sorry for keeping you guys busy with such a mistake ;)
Dec 4 '07 #8
Sorry for keeping you guys busy with such a mistake ;)

No apologies necessary, especially since you reported the final
outcome. Now anybody searching on that message will find a complete
thread and a lesson learned.

rick
Dec 5 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: squash | last post by:
I am a little annoyed at why such a simple program in Perl is causing so much difficulty for python, i.e: $a += 200000 * 140000; print $a;
1
by: Daves | last post by:
a simple aspx page just needs to send a particular .txt file to stream so that it opens up in Notepad on client side. Using ContentType = "text/plain" it still opens in IE browser as a html file,...
7
by: jacobevans | last post by:
i need some help opening a text file and having the contents in that file add to a list. for example a user types '/addlist C:/text.txt'. the program takes the c:/text.txt and adds the items to...
1
by: simon_s_li | last post by:
Hi, Does anyone have any coding example on how to select a text or csv file (file open diagloue box) from my local drive and then read it in the backend using some kind of inputsteam? Thanks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.