[Tutor] RE: File path

Homer Ellison ellisonh@prodigy.net
Tue Jun 10 03:23:03 2003


Thank you to those who responded. Your answers are a great help, since I
couldn't find a clear explanation in the books I've been using for
reference.

All the best,
Homer


--__--__--

Message: 3
Date: Mon, 09 Jun 2003 12:34:18 -0400
From: Kirk Bailey <idiot1@netzero.net>
Organization: Silas Dent Memorial Cabal of ERIS Esoteric and hot dog
boiling  society
CC: Python Tutor List <tutor@python.org>
Subject: Re: [Tutor] File path

When it is in the current working directory (cwd), you don't. Just open
the file.

When it is someplace else, it is pretty safe to declare the complete
path.

f1=open('c:\my documents\foobot\foobot.config','r')

SOME operations permit relative addessing, but your milage may vary.

if os.exists('./lists/mylist'):
	do.something('yes')
else:
	do.something('no')

When it is in the cwd you do not declare a path at all:

f1=open('history.txt','r')

absolute addressing is safe and dependable. Odd that SOME functions
allow relative 
addressing, and some don't.


Homer Ellison wrote:
> Hello,
>  
> I'm new to programming in Python (and to object-oriented programming 
> in
> general). The programming experience I have is from a long time ago,
so 
> I'm going to have many questions.
>  
> How do I specify the file path within my code to access files for
> reading and writing? I'm using a PC with 32-bit Windows.
>  
> Thank you,
> Homer
>