[Tutor] Opening files?

alan.gauld@bt.com alan.gauld@bt.com
Wed Mar 26 13:14:08 2003


> When I want to try and open(import?) and read files, what are 
> the best commands to use?
> 

Older python versions used open() to open a file, newer 
versions (2.2.x) use file(). open() worls on both so if 
backwards compatibility matters use open().

> Also, how do I specify the path that python needs to follow 
> to open the file?

Not sure what you mean here. You specify it in the form that your operating 
system expects. You can go to town on this and use various OS independant 
symbols (from the os module?). Normally you just pass the full path to 
open() or file()

> I am trying to manipuilate text(.txt) files with python 2.2.2.

You might find the file handling topic in my tutorial useful.

Alan g.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld/