473,597 Members | 2,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.s mo', '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 1397
I believe you want:

import os
f = open(os.path.jo in(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.s mo', '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.s mo', '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.s mo', '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.s mo', '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
3141
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 it. max_execution_time = 5000 ; Maximum execution time
0
1547
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 pages by program reloading. Web Memory is the basis for an Open Source e-commerce front end that could reduce web congestion and simplify online shopping. If too many people use this technique, then it will not work for anyone. Bandwidth for Web...
7
12958
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 needs to access the class defined in my second file and I can't figure out how to work this right. if I use an #include in my third file, my Main gives me a compile-time class redefinition error. if I don't, the third file can't "see" the second
5
2721
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. - Tried compacting / repairing but same situation.
1
341
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
5251
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(); return 0; }
5
7842
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), after some investgation i found out that most of it being consumed by filesystem caching... thanks to Liam and Phil Sherman for their valuable suggestions. Is it safe to turn off filesystem caching on every tablespaceon the server(i.e. DIO) ??...
4
2178
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 they are not maximized when they load. Unfortunately, this seems to have had the consequence of removing them from the Windows taskbar, which makes navigating between open forms more difficult. How would you developers deal with navigation between...
5
7942
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, it can open the file. However, when I run Php5 I (now) get this error message: "Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?" This is new. Last time I messed with this, I merely got:
0
7959
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8263
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5842
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3917
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2393
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1492
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.