Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 22nd, 2005, 4:10 PM   #1
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
open()

Well, I'm learning python. I'm using my windows PC for it.
Now, here's what I'm putting in and the result:
>>> f=open('M:\programming\read.txt','r+')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 2] No such file or directory: 'M:\\programming\read.txt'
>>>

I know that the file and location is right, I'm just not sure if I'm putting it in right. Thanks for any help.
Eryk is offline   Reply With Quote
Old Aug 22nd, 2005, 4:26 PM   #2
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
'M:\\programming\read.txt'

you missed a backslash before read.txt
Polyphemus_ is offline   Reply With Quote
Old Aug 22nd, 2005, 4:47 PM   #3
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
Thank you very much, working beautifully now.
Eryk is offline   Reply With Quote
Old Aug 22nd, 2005, 7:53 PM   #4
hydroxide
Programmer
 
Join Date: Apr 2005
Posts: 73
Rep Power: 4 hydroxide is on a distinguished road
Quote:
Originally Posted by Eryk
Well, I'm learning python. I'm using my windows PC for it.
Now, here's what I'm putting in and the result:
>>> f=open('M:\programming\read.txt','r+')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
IOError: [Errno 2] No such file or directory: 'M:\\programming\read.txt'
>>>

I know that the file and location is right, I'm just not sure if I'm putting it in right. Thanks for any help.
when dealing with paths, use raw strings:
f=open(r'M:\programming\read.txt','r+')
or use os.path:
import os
fname = os.path.join("M:\\", "whereever", "foo.txt")
f=open(fname, "r+")

--OH.
hydroxide is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:20 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC