[Tutor] absolute locations
Alan Gauld
alan.gauld at blueyonder.co.uk
Fri Jan 9 02:59:59 EST 2004
> > >>> fileName = os.path.join("c:\\Documents and Settings",
> > "Christopher Spears", "My Documents", "python", "unit4.txt")
>
> Well, that's a way that works, but I, for one, am not
> completely convinced that the first way shouldn't work.
> Why should someone be forced to type the first "\\",
> especially since that might change on a per-os basis?
Because C:Documets....
is a perfectly valid path(*) and if join() always put a \\ after
the drive letter you would not be able to create a relative path
on another disk!
If you want the path to be absolute you need to make it so.
(*)For those not accustomed to DOS and its peculiarities,
the OS stores the current location *per disk*, thus:
C:> cd WINDOWS\SYSTEM32
C:\WINDOWS\SYSTEM32> D:
D:> dir C:
....contents of WINDOWS\SYSTEM32 directory....
....
So although I am now in the root of D:, Windows knows that
my last C: location was C:\WINDOWS\SYSTEM32 and when I ask
for a dir listing thats the directory it tells me about.
And if I change back to the C: drive thats where it puts me.
D:> C:
C:\WINDOWS\SYSTEM32> CD D:\TEMP
C:\WINDOWS\SYSTEM32> D:
D:\TEMP>
Similarly if I CD on the D drive while located on C it does
not move me into D: it simply changes the current D position,
so that when I next move to D I move into the new position,
not to root.
Thats why a relative path can begin with the drive letter!
Alan G.
More information about the Tutor
mailing list