473,387 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

open file in dir independently of operating system

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

Jul 19 '05 #1
5 1388
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
aw*@fluent.com
Phone: 603-643-2600, ext. 757
Fax: 603-643-1721
www.fluent.com
************************************
Jul 19 '05 #2
Hi,
it`s

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

HTH,
Gerald

Joerg Schuster schrieb:
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


--
GPG-Key: http://keyserver.veridis.com:11371/search?q=0xA140D634

Jul 19 '05 #3
Thanks, Andrew and Gerald.

Jörg

Jul 19 '05 #4
Gerald Klix schrieb:
Hi,
it`s

import os
f = open( os.path.join( dir , 'configuration.smo' ), 'r' )
*nix-heads everywhere?

For a text file, I would prefer:
f = open( os.path.join( dir , 'configuration.smo' ), 'U' )

and for a binary file:
f = open( os.path.join( dir , 'configuration.smo' ), 'rb' )

That way it also works on Windows.

Thomas
Joerg Schuster schrieb:
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

Jul 19 '05 #5
Joerg Schuster schrieb:
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?


Did You check this out on Windows? My experience with *nix paths is
that they work.
open("C:/bla.txt")

<open file 'C:/bla.txt', mode 'r' at 0x026B4A20>

Kay

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: praba kar | last post by:
Dear All, I have one doubt. Is there python.ini file like php.ini in Php? Actually php.ini file controls many aspects of PHP's behavior. The following details of php.ini will explain about...
0
by: Lane Friesen | last post by:
I've developed a new form of client-based, secure 'Web Memory' that uses the JAVA or dotNET VM to launch a 'terminate and stay resident' program fragment that maintains persistence between web...
7
by: A_StClaire_ | last post by:
hi, I'm working on a project spanning five .cpp files. each file was used to define a class. the first has my Main and an #include for each of the other files. problem is my third file...
5
by: elieli_132 | last post by:
Hi, My problem is the following: Made changes to code in form and closed the form. Now unable to open / design the form. - Tried copying and pasting - the new one does not open /display....
1
by: mbahl | last post by:
Is there a CRT method to find if a file is open. Or a way to get the refcount on itz open handles.
6
by: PengYu.UT | last post by:
The following code open the file "example.txt" in the current directory. int main () { ofstream myfile; myfile.open ("example.txt"); myfile << "Writing this to a file.\n"; myfile.close();...
5
by: Raj | last post by:
What is the purpose of file system caching while creating a tablespace? Memory on the test server gets used up pretty quickly after a user executes a complex query(database is already activated),...
4
by: robert.waters | last post by:
Hello, I have a main form that is maximized when my application loads; this main form contains links to all other forms. I've had to specify the Popup property of these other forms, so that...
5
by: Chuck Anderson | last post by:
I run Apache 2.0.55, and Php (both 4.4.1 and 5.2.5) on my home PC (Windows XP). One of the scripts that I run daily needs to access a secure URL (https://..............). When I am running Php4,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.