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('Pictures', '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.jpg'
Thanks,
Marcin 6 16949
On Oct 19, 6:00*am, Marcin201 <marcin...@gmail.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('Pictures', '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.jpg'
Note that os.path.join('Pictures', '01.jpg') returns 'Pictures/01.jpg'
on Unix.
Note that 'Pictures\\01.jpg' == r'Pictures\01.jpg' i.e. there is only
one backslash.
Have you considered unix_path = windows_path.replace('\\', '/')?
In message
<5b**********************************@m73g2000hsh. googlegroups.com>,
Marcin201 wrote:
os.path.join('Pictures', '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.jpg'
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('Pictures', '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.jpg'
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...@vitalEsafe.comwrote:
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('Pictures', '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.jpg'
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.canterbury.ac.nzwrote:
> 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...
|
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...
|
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);...
|
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")...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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,...
|
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...
|
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...
| |