open file in dir independently of operating system

Andrew Bushnell awb at fluent.com
Wed May 25 07:42:55 EDT 2005


I believe you want:

import os
f = open(os.path.join(dir, 'configuration.smo'), 'r')

...


Joerg Schuster wrote:

> Hello,
> 
> 
> I want to open the file 'configuration.smo' that is in directory dir.
> Yet, I don't know on which os my program is being run. On Unix I would
> say:
> 
> f = open(dir + '/configuration.smo', 'r')
> 
> What is the os-independent version of this line?
> 
> (I have read the manual of the module os, but I didn't see how to do
> it.)
> 
> 
> Jörg Schuster
> 

-- 
************************************
Andrew Bushnell
Lead Development Engineer
Fluent Inc.
10 Cavendish Court
Centerra Resource Park
Lebanon, NH  03766
awb at fluent.com
Phone: 603-643-2600, ext. 757
Fax: 603-643-1721
www.fluent.com
************************************



More information about the Python-list mailing list