Re: os.path.normpath question

2010-06-08 Thread Duncan Booth
Bart  wrote:

> I'm using this and ran across backslash issues in one of my paths.
> 
>      archpath = os.path.normpath('E:\foo\FTP\HLS\archive')
> 
> was translating to:
> 
>  E:\lsfprod\law\uch_interfaces\FTP\HLSrchive
> 
> which caused me to start using the 'raw' declaration before the path
> string like this:
> 
>  archpath = os.path.normpath(r'E:\foo\FTP\HLS\archive')
> 
> Is this the right way to use this?
> 

If you want to use raw strings for Windows paths then you need to be aware 
that you cannot end a raw string with a backslash.

In most cases you can just use forward slashes instead and then you don't 
need to worry about escaping them:

archpath = os.path.normpath('E:/foo/FTP/HLS/archive')


Or better still, don't put hardwired paths into your application, put them 
all in a config file.

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.normpath question

2010-06-07 Thread Peter Otten
Bart wrote:

> I'm using this and ran across backslash issues in one of my paths.
> 
>      archpath = os.path.normpath('E:\foo\FTP\HLS\archive')
> 
> was translating to:
> 
>  E:\lsfprod\law\uch_interfaces\FTP\HLSrchive
> 
> which caused me to start using the 'raw' declaration before the path
> string like this:
> 
>  archpath = os.path.normpath(r'E:\foo\FTP\HLS\archive')
> 
> Is this the right way to use this?

Yes, but os.path.normpath() has nothing to with it. It's just how Python 
translates any string literal to a string object, see

http://docs.python.org/reference/lexical_analysis.html#string-literals

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


os.path.normpath question

2010-06-07 Thread Bart
I'm using this and ran across backslash issues in one of my paths.

 archpath = os.path.normpath('E:\foo\FTP\HLS\archive')

was translating to:

 E:\lsfprod\law\uch_interfaces\FTP\HLSrchive

which caused me to start using the 'raw' declaration before the path
string like this:

 archpath = os.path.normpath(r'E:\foo\FTP\HLS\archive')

Is this the right way to use this?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More precise document on os.path.normpath()

2009-11-23 Thread Lie Ryan

Peng Yu wrote:

After I tried os.path.normpath(), it is clear that the function
doesn't return the trailing '/', if the path is a directory. But this
fact is not documented. Should this be documented in future release of
python.

Also, I found the documentation of some functions in os.path are not
clear. I have to try them in order to understand them for corner
cases. I'm wondering if I can join the people who maintain the
document to help improve it.


os.path is designed for OS-agnostic path manipulation. The textual 
representation of the output of os.path is irrelevant. If a trailing '/' 
doesn't affect the ability to open the directory or file or os.path.join 
or whatever, it is irrelevant to os.path. If the trailing / does affect 
those abilities, though, it is a bug in os.path.

--
http://mail.python.org/mailman/listinfo/python-list


Re: More precise document on os.path.normpath()

2009-11-23 Thread Carl Banks
On Nov 23, 5:59 pm, Benjamin Kaplan  wrote:
> On Mon, Nov 23, 2009 at 8:52 PM, Peng Yu  wrote:
> > After I tried os.path.normpath(), it is clear that the function
> > doesn't return the trailing '/', if the path is a directory. But this
> > fact is not documented. Should this be documented in future release of
> > python.
>
> > Also, I found the documentation of some functions in os.path are not
> > clear. I have to try them in order to understand them for corner
> > cases. I'm wondering if I can join the people who maintain the
> > document to help improve it.
>
> Just file a bug report listing what part you find unclear and what you
> suggest they put to clarify it.

The documentation does not and should not try to document every little
detail of every function.

For that matter, nor should comp.lang.python.

Python is open source, anyone can look at the implementation to see
how it behaves.  The source code is the right place to seek answers
about arcane minutae like when os.path.normpath appends a backslash.
Not the Python docuementation, and definitely not this newsgroup.


Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More precise document on os.path.normpath()

2009-11-23 Thread Benjamin Kaplan
On Mon, Nov 23, 2009 at 8:52 PM, Peng Yu  wrote:
> After I tried os.path.normpath(), it is clear that the function
> doesn't return the trailing '/', if the path is a directory. But this
> fact is not documented. Should this be documented in future release of
> python.
>
> Also, I found the documentation of some functions in os.path are not
> clear. I have to try them in order to understand them for corner
> cases. I'm wondering if I can join the people who maintain the
> document to help improve it.
> --

Just file a bug report listing what part you find unclear and what you
suggest they put to clarify it.

> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


More precise document on os.path.normpath()

2009-11-23 Thread Peng Yu
After I tried os.path.normpath(), it is clear that the function
doesn't return the trailing '/', if the path is a directory. But this
fact is not documented. Should this be documented in future release of
python.

Also, I found the documentation of some functions in os.path are not
clear. I have to try them in order to understand them for corner
cases. I'm wondering if I can join the people who maintain the
document to help improve it.
-- 
http://mail.python.org/mailman/listinfo/python-list


os.path.normpath() for URLs?

2008-08-04 Thread Robert Dailey
Hi,

I'm currently trying to parse relative URLs, but I want to make them
absolute. In other words, I want to normalize the URLs. However, I don't
want to have to write this logic myself if it is already provided. I was
thinking of somehow tricking os.path.normpath() as a last resort. This is
for subversion URLs, for those wondering. Basically, I need to turn the
following URL:

svn://myserver/foo/bar/trunk/../tags

Into this:

svn://myserver/foo/bar/tags


Does anyone know a way I can do this? Thanks.
--
http://mail.python.org/mailman/listinfo/python-list

Re: os.path.normpath bug?

2007-06-14 Thread billiejoex
On 14 Giu, 22:35, Michael Hoffman <[EMAIL PROTECTED]> wrote:

> Intentional.
>
> http://en.wikipedia.org/wiki/Path_(computing)#Universal_Naming_Conven...
> --
> Michael Hoffman

Got it.
Thank you.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.normpath bug?

2007-06-14 Thread Michael Hoffman
billiejoex wrote:
> Hi there,
> I've noticed that os.path.normpath does not collapse redundant
> separators if they're located at the beginning of the string:
> 
>>>> print os.path.normpath('/a//b//c')
> \a\b\c
>>>> print os.path.normpath('//a//b//c')
> \\a\b\c
> 
> Is it intentional or is it a bug?

Intentional.

http://en.wikipedia.org/wiki/Path_(computing)#Universal_Naming_Convention
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


os.path.normpath bug?

2007-06-14 Thread billiejoex
Hi there,
I've noticed that os.path.normpath does not collapse redundant
separators if they're located at the beginning of the string:

>>> print os.path.normpath('/a//b//c')
\a\b\c
>>> print os.path.normpath('//a//b//c')
\\a\b\c

Is it intentional or is it a bug?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.normpath

2006-08-17 Thread placid

placid wrote:
> Hi all,
>
> I was just wondering if there is a anti-os.path.normpath function? For
> example if i have the path "C:\Program Files\Games" i want to
> anti-os.path.normpath is so that it becomes "C:\\Program Files\\Games"
> ?
>
> Cheers

Ahh ignore my post. I was using abspath, and normpath is what i what.

Doh, stupid me!

Cheers

-- 
http://mail.python.org/mailman/listinfo/python-list


os.path.normpath

2006-08-17 Thread placid
Hi all,

I was just wondering if there is a anti-os.path.normpath function? For
example if i have the path "C:\Program Files\Games" i want to
anti-os.path.normpath is so that it becomes "C:\\Program Files\\Games"
?

Cheers

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.normpath

2006-08-16 Thread Graham Dumpleton
Hari Sekhon wrote ..
> [EMAIL PROTECTED] wrote:
> > [EMAIL PROTECTED] wrote:
> >   
> >> I am using a windows box and passing a string like "../foo/../foo2"
> to
> >> normpath which then returns "..\\foo2". But if this string is going
> >> into a webpage link it should really be "../foo".
> >>
> >> Is there any way to tell os.path.normpath to act like we are an a unix
> >> style box?
> >> 
> >
> > Use posixpath.normpath() instead.
> >
> >   
> I can't seem to find posixpath in the docs, but I can import posixpath
> and a dir shows it does indeed have a normpath.

Quoting:

  http://www.python.org/doc/2.3.5/lib/node750.html

it says:

  posixpath
  -- Implementation of os.path on POSIX.

What it provides is therefore documented by os.path module. The posixpath
module is still accessible on non POSIX platforms though.

Graham

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.normpath

2006-08-16 Thread Hari Sekhon




[EMAIL PROTECTED] wrote:

  [EMAIL PROTECTED] wrote:
  
  
I am using a windows box and passing a string like "../foo/../foo2" to
normpath which then returns "..\\foo2". But if this string is going
into a webpage link it should really be "../foo".

Is there any way to tell os.path.normpath to act like we are an a unix
style box?

  
  
Use posixpath.normpath() instead.

  

I can't seem to find posixpath in the docs, but I can import posixpath
and a dir shows it does indeed have a normpath.

-h



-- 
http://mail.python.org/mailman/listinfo/python-list

Re: os.path.normpath

2006-08-09 Thread grahamd

[EMAIL PROTECTED] wrote:
> I am using a windows box and passing a string like "../foo/../foo2" to
> normpath which then returns "..\\foo2". But if this string is going
> into a webpage link it should really be "../foo".
>
> Is there any way to tell os.path.normpath to act like we are an a unix
> style box?

Use posixpath.normpath() instead.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.normpath

2006-08-09 Thread Gabriel Genellina

At Wednesday 9/8/2006 15:45, [EMAIL PROTECTED] wrote:


I am using a windows box and passing a string like "../foo/../foo2" to
normpath which then returns "..\\foo2". But if this string is going
into a webpage link it should really be "../foo".


You could just .replace('\\','/') on the resulting string. Or use the 
urlparse module.



Is there any way to tell os.path.normpath to act like we are an a unix
style box?


The fact than '/' is used as a path separator both on unix and on 
HTTP URLs should be considered as a mere coincidence (in fact it isn't...)
URLs dont necesarily point to a real file on a real file system (Zope 
is an example).




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


-- 
http://mail.python.org/mailman/listinfo/python-list

Re: os.path.normpath

2006-08-09 Thread BartlebyScrivener

[EMAIL PROTECTED] wrote:

> But if this string is going into a webpage link

http://docs.python.org/lib/module-urlparse.html

rd

-- 
http://mail.python.org/mailman/listinfo/python-list


os.path.normpath

2006-08-09 Thread nathanbullock
I am using a windows box and passing a string like "../foo/../foo2" to
normpath which then returns "..\\foo2". But if this string is going
into a webpage link it should really be "../foo".

Is there any way to tell os.path.normpath to act like we are an a unix
style box?

What about in the new python 2.5 Path class?

Nathan

-- 
http://mail.python.org/mailman/listinfo/python-list