[Tutor] absolute locations
Gustavo Campanelli
birdiepage at ciudad.com.ar
Thu Jan 8 15:22:47 EST 2004
Christopher Spears wrote:
>Grrr!
>
>I'm trying to open up a file with the following
>absloute path in Windows 2000:
>
>C:\Documents and Settings\Christstopher Spears\My
>Documents\python\unit4.txt
>
>So I enter the following in IDLE:
>
>
>
>>>>import os
>>>>fileName = os.path.join("c:", "Documents and
>>>>
>>>>
>Settings", "Christopher Spears", "My Documents",
>"python", "unit4.txt")
>
>
>>>>fileobject = open(fileName, 'r')
>>>>
>>>>
>
>Traceback (most recent call last):
> File "<pyshell#2>", line 1, in -toplevel-
> fileobject = open(fileName, 'r')
>IOError: [Errno 2] No such file or directory:
>'c:Documents and Settings\\Christopher Spears\\My
>Documents\\python\\unit4.txt'
>
>I know unit4.txt is there, but I can't seem to
>convince python of that! What is up with \\ anyway?
>
>=====
>"I'm the last person to pretend that I'm a radio. I'd rather go out and be a color television set."
>-David Bowie
>
>"Who dares wins"
>-British military motto
>
>"Far more creativity, today, goes into the marketing of products than into the products themselves..."
>-"Pattern Recognition" by William Gibson
>
I don't have experience with Python relating to the OS module, but I'll
suggest two possible failures here.
1) you are trying to get data from another user without reading
permissions (not likely but possible)
2) and I'm preety sure this is it, you are trying to reach C:\Documents
and Settings\Christstopher Spears\My Documents\python\unit4.txt, wich is
an absolute path, but your Python is trying to locate 'c:Documents and
Settings\\Christopher Spears\\My Documents\\python\\unit4.txt', which
lacks the \ right after the c: thus making itself a relative path.
Gedece, still a Python newbie
More information about the Tutor
mailing list