Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Richard D. Moores
On Sun, Jul 31, 2011 at 10:34, Peter Otten <__pete...@web.de> wrote: > > Richard D. Moores wrote: > > >> What happens if the path looks like > >> > >> r"C:relative\path\to\my\file.txt" > >> > >> or > >> > >> r"C:/mixed\slashes.txt"? > > > > Not quite sure what the intent of your question is, but al

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Peter Otten
Richard D. Moores wrote: >> What happens if the path looks like >> >> r"C:relative\path\to\my\file.txt" >> >> or >> >> r"C:/mixed\slashes.txt"? > > Not quite sure what the intent of your question is, but all the paths > I want to modify are full, with only back slashes. If you invoke your fwd2bk

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Sergey
Nice! That's what I've been expecting. Thanks. Your one string command is tiny and complete. And elegant. Final desicion? Or it could be something better and more professional? So we have removed regexps and everything is fine now. Yes? On Mon, 01 Aug 2011 02:37:09 +1000 Steven D'Aprano wrote

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Steven D'Aprano
Sergey wrote: Gotcha! http://pymon.googlecode.com/svn/tags/pymon-0.2/Internet/rsync.py 231-239 strings ## code ## def convertPath(path): # Convert windows, mac path to unix version. separator = os.path.normpath("/") if separator != "/": path = re.sub(re.e

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Sergey
Haha. Works! Happy help you. Ask gurus about regexps. I know they have an opinion about its speed and optimization. So they can try to criticise. But the problem is solved. It's good. On Sun, 31 Jul 2011 09:18:33 -0700 "Richard D. Moores" wrote > > Nice! > > I went with > > > import os.pat

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Richard D. Moores
On Sun, Jul 31, 2011 at 08:59, Sergey wrote: > Gotcha! > http://pymon.googlecode.com/svn/tags/pymon-0.2/Internet/rsync.py > 231-239 strings > > ## code ## > > def convertPath(path): >        # Convert windows, mac path to unix version. >        separator = os.path.normpath("/") >        if separat

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Sergey
Gotcha! http://pymon.googlecode.com/svn/tags/pymon-0.2/Internet/rsync.py 231-239 strings ## code ## def convertPath(path): # Convert windows, mac path to unix version. separator = os.path.normpath("/") if separator != "/": path = re.sub(re.escape(separator)

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Richard D. Moores
On Sun, Jul 31, 2011 at 03:34, Peter Otten <__pete...@web.de> wrote: > Sandip Bhattacharya wrote: > >> On Sat, Jul 30, 2011 at 10:28:11PM -0700, Richard D. Moores wrote: >>> File "c:\P32Working\untitled-5.py", line 2 >>>    return path.replace('\', '/') >>>                                ^ >>> Synt

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Richard D. Moores
On Sun, Jul 31, 2011 at 03:34, Peter Otten <__pete...@web.de> wrote: > > Sandip Bhattacharya wrote: > > > On Sat, Jul 30, 2011 at 10:28:11PM -0700, Richard D. Moores wrote: > >> File "c:\P32Working\untitled-5.py", line 2 > >>    return path.replace('\', '/') > >>                                ^ >

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Sergey
Maybe something useful could be find in urllib? It can open local files. And UNIX slashes are equal to Web slashes. http://docs.python.org/release/3.2.1/library/urllib.request.html#urllib.request.URLopener -- class urllib.request.URLopener(proxies=None, **x509) Base class for opening and readi

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Peter Otten
Sandip Bhattacharya wrote: > On Sat, Jul 30, 2011 at 10:28:11PM -0700, Richard D. Moores wrote: >> File "c:\P32Working\untitled-5.py", line 2 >>return path.replace('\', '/') >>^ >> SyntaxError: EOL while scanning string literal >> Process terminated with an exit

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Richard D. Moores
On Sat, Jul 30, 2011 at 23:32, Sandip Bhattacharya wrote: > > On Sat, Jul 30, 2011 at 10:28:11PM -0700, Richard D. Moores wrote: > > File "c:\P32Working\untitled-5.py", line 2 > >    return path.replace('\', '/') > >                                ^ > > SyntaxError: EOL while scanning string liter

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Steven D'Aprano
Richard D. Moores wrote: File "c:\P32Working\untitled-5.py", line 2 return path.replace('\', '/') ^ SyntaxError: EOL while scanning string literal Others have already told you how to solve the immediate problem (namely, escape the backslash), but I'd like to

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Steven D'Aprano
Sandip Bhattacharya wrote: Generally, converting slashes manually should be kept at a minimum. You should be using library functions as much as possible. The experts here can correct me here, but this is a roundabout way I would be doing this: str.replace('\\', '/') is a perfectly fine library

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-30 Thread Sandip Bhattacharya
On Sat, Jul 30, 2011 at 10:28:11PM -0700, Richard D. Moores wrote: > File "c:\P32Working\untitled-5.py", line 2 >return path.replace('\', '/') >^ > SyntaxError: EOL while scanning string literal > Process terminated with an exit code of 1 The first backslash up

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-30 Thread Alexander Etter
On Jul 31, 2011, at 1:28, "Richard D. Moores" wrote: > 64-bit Vista > Python 3.2.1 > > I would like to write a function that would take a path such as > 'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf' > and return 'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf' . I've > tri

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-30 Thread ian douglas
Try a double backslash replace('\\','/') On Jul 30, 2011 10:30 PM, "Richard D. Moores" wrote: > 64-bit Vista > Python 3.2.1 > > I would like to write a function that would take a path such as > 'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf' > and return 'C:/Users/Dick/Desktop/Documents

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-30 Thread Dharmit Shah
Ruchard, Try return path.replace('\\', '/'). That gave me the output desired by you. I don't know the reason. But I guess it's because \ is used as escape character. I am sure someone in the list will point out the accurate reason. On Sun, Jul 31, 2011 at 10:58 AM, Richard D. Moores wrote: > 64-

[Tutor] How to replace the '\'s in a path with '/'s?

2011-07-30 Thread Richard D. Moores
64-bit Vista Python 3.2.1 I would like to write a function that would take a path such as 'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf' and return 'C:/Users/Dick/Desktop/Documents/Notes/College Notes.rtf' . I've tried this: def test(path): return path.replace('\', '/') print(test(