Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 18th, 2004, 10:33 PM
caroundw5h caroundw5h is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 181 caroundw5h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 55 m 53 sec
Reputation Power: 0
file error

Can anyone tell me why i keep getting the following syntax errors:
Code:
f = open( r "C:\Python23\test.txt")
SyntaxError: invalid syntax
>>> f = open( r 'C:Python23\test.txt')
SyntaxError: invalid syntax


i've saved the text file in python's path and if i don't give open a path, just the name of the file, it opens fine. What is the invalid syntax here?
__________________
"In theory, there is no difference between theory and practice.
But, in practice, there is."


Reply With Quote
  #2  
Old March 18th, 2004, 11:39 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
those spaces are invalid syntax, the "r" has to be the character immediately preceding the quotes if you want to use raw strings

also, use file and not open, open is deprecated
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
  #3  
Old March 19th, 2004, 03:49 AM
Johie Johie is offline
Python/RDF Freak
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 14 Johie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Johie
Hi maybe this works:

Code:
f = open("C:\Python23\test.txt", "r")

Reply With Quote
  #4  
Old March 19th, 2004, 07:30 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
A combination of the two replies:
Code:
f = file(r"C:\Python23\test.txt", "r")


Read access is the default mode so you could leave the comma "r" bit out, but I wouldn't.

Grim
__________________
*** Experimental Python Markup CGI V2 ***

Last edited by Grim Archon : March 19th, 2004 at 07:33 AM.

Reply With Quote
  #5  
Old March 19th, 2004, 09:09 AM
caroundw5h caroundw5h is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 181 caroundw5h User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 55 m 53 sec
Reputation Power: 0
Thanks guys. Appreaciate your help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > file error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway