Is there an built-in functionality in python to convert Windows paths
to Unix paths? I am running into problems when creating data files on
Windows and the running them on a Unix platform. I create paths using
os.path.join.
os.path.join('P ictures', '01.jpg') returns 'Pictures\\01.. jpg' on
Win. When I read files created on Win under Unix this is a problem,
python cannot open 'Pictures\\01.j pg'
Thanks,
Marcin 6 17026
On Oct 19, 6:00*am, Marcin201 <marcin...@gmai l.comwrote:
Is there an built-in functionality in python to convert Windows paths
to Unix paths? *I am running into problems when creating data files on
Windows and the running them on a Unix platform. *I create paths using
os.path.join.
os.path.join('P ictures', '01.jpg') returns 'Pictures\\01.. jpg' on
Win. *When I read files created on Win under Unix this is a problem,
python cannot open 'Pictures\\01.j pg'
Note that os.path.join('P ictures', '01.jpg') returns 'Pictures/01.jpg'
on Unix.
Note that 'Pictures\\01.j pg' == r'Pictures\01.j pg' i.e. there is only
one backslash.
Have you considered unix_path = windows_path.re place('\\', '/')?
In message
<5b************ *************** *******@m73g200 0hsh.googlegrou ps.com>,
Marcin201 wrote:
os.path.join('P ictures', '01.jpg') returns 'Pictures\\01.. jpg' on
Win. When I read files created on Win under Unix this is a problem,
python cannot open 'Pictures\\01.j pg'
But it can on Windows, right?
os.path contains functions specific to the _current_ platform (the one your
script is running on). If you're trying to perform pathname manipulations
on behalf of another platform, you shouldn't be using os.path.
Marcin201 wrote:
Is there an built-in functionality in python to convert Windows paths
to Unix paths? I am running into problems when creating data files on
Windows and the running them on a Unix platform. I create paths using
os.path.join.
os.path.join('P ictures', '01.jpg') returns 'Pictures\\01.. jpg' on
Win. When I read files created on Win under Unix this is a problem,
python cannot open 'Pictures\\01.j pg'
Thanks,
Marcin
I use posixpath when I want to "force" forward slashes that I know will work on
Linux. Actually the forward slashes work fine on Windows also (undocumented
feature of Windows).
-Larry
On Oct 20, 4:47*pm, Larry Bates <larry.ba...@vi talEsafe.comwro te:
Marcin201 wrote:
Is there an built-in functionality in python to convert Windows paths
to Unix paths? *I am running into problems when creating data files on
Windows and the running them on a Unix platform. *I create paths using
os.path.join.
os.path.join('P ictures', '01.jpg') returns 'Pictures\\01.. jpg' on
Win. *When I read files created on Win under Unix this is a problem,
python cannot open 'Pictures\\01.j pg'
Thanks,
Marcin
I use posixpath when I want to "force" forward slashes that I know will work on
Linux. *Actually the forward slashes work fine on Windows also (undocumented
feature of Windows).
FYI, in Windows the standard is for commandline options to begin with
a slash, eg dir /b, but as long as the path doesn't begin with one
you'll be OK. :-)
Dennis Lee Bieber wrote:
The command line is the only place the slash direction has any
effect any way... Avoid os.system(), subprocess with shell = True, and
forward is safe in any position.
I'm not sure that's quite true. On Windows, it's not the
shell that splits up the command line into arguments, it's
the program being run. So you need to avoid any kind of
exec or spawn operation, whether it goes through the shell
or not, unless you know the program being run isn't going
to interpret '/' as an option.
--
Greg
greg <gr**@cosc.cant erbury.ac.nzwro te:
> Dennis Lee Bieber wrote:
>The command line is the only place the slash direction has any effect any way... Avoid os.system(), subprocess with shell = True, and forward is safe in any position.
I'm not sure that's quite true. On Windows, it's not the shell that splits up the command line into arguments, it's the program being run. So you need to avoid any kind of exec or spawn operation, whether it goes through the shell or not, unless you know the program being run isn't going to interpret '/' as an option.
Well, you actually said the same thing as Dennis here, in a slightly
different way.
The executive summary here is that the Windows APIs all accept either
forward or backward slashes just fine. The trouble happens when you start
using command lines, just as Dennis said.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: gry |
last post by:
I want to write some kind of install script for my python app that
will add c:\cygwin\usr\bin to the system path. I don't want
to walk around to 50 PC's and twiddle through the GUI to:
My Computer --> Control Panel --> System --> Advanced --> Environment
How can a python, or even a .bat script modify the system PATH?
It doesn't appear to be in the registry.
|
by: Larthusza |
last post by:
I've been called out of retirement to make a small database application for
my local crinklies group and am a bit rusty. This is not strictly anything
to do with Access per se but that is what I am using and I'm sure it is no
great challenge to the excellent people who meet here.
I have made my application in Delphi which uses MS Access tables and which
are very small, 100 or so records, which runs across a network from a UNIX
server...
|
by: e_matthes |
last post by:
Hello,
I have a function which uses a regular expression to validate text
input. Here's a short code sample testing the regex:
<?php
$dirty = "hello";
$clean = getCleanText($dirty, 0,50);
print "<br>dirty: $dirty<br>clean: $clean";
|
by: eeriehunk |
last post by:
Hi,
I am new to Javascript and I developed a code and one of the functions needs a path (a directory location) as its input. It works fine for all windows paths
get _path("c:/somedir/somedir") but when i transfered this file on to a unix system and when I replace this path with a unix path it does not work. I am very sure I am giving the wrong path format. I tried all the possible ways, I am not sure what is missing. ...
|
by: eeriehunk |
last post by:
Hi,
1.what if my Html and my script are on a unix server and I have to provide a unix path, what would the unix path format be?
var f = fs.GetFolder(Server.MapPath("/bin/somedir/somedir/");
or can i directly use
var f = fs.GetFolder("/bin/somedir/somedir/");
but the above two do not work. They work fine on windows with Windows path
var f = fs.GetFolder("c:/");
and not with unix path. Please help.
| |
by: Vinod Sadanandan |
last post by:
Cross Platform Migration An Unproblematic Approach (Windows-UNIX ) Oracle 10\11g
The principal restriction on cross-platform transportable database is that the source and destination platform must share the same endian format.
Redo log files and control files from the source database are not transported to destination database . New control files and redo log files are created for the new database during the transport process, and an ...
|
by: Mirko Vogt |
last post by:
Hey,
it seems that the socket-module behaves differently on unix / windows when a timeout is set.
Here an example:
# test.py
import socket
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print 'trying to connect...'
|
by: Mirko Vogt |
last post by:
Gabriel Genellina wrote:
Hey, this is strange.
Linux:
$ python --version
Python 2.5.2
$
Windows:
|
by: gskbond |
last post by:
I have a template file whose line reads as:
CREATE TABLESPACE "CUSTTBS" LOGGING DATAFILE '{DBFILE_PATH}cust.dbf' SIZE 1000M REUSE AUTOEXTEND ON NEXT 100M MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO ;
The place holder is {DBFILE_PATH}
I am replacing this by contents in a perl array which has paths in it
The code to open a file replace contents and write new file is:
|
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...
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |