[Tutor] Regex for Filesystem path (Asad)

Albert-Jan Roskam sjeik_appie at hotmail.com
Thu Nov 8 10:51:39 EST 2018








From: Tutor <tutor-bounces+sjeik_appie=hotmail.com at python.org> on behalf of Alan Gauld via Tutor <tutor at python.org>
Sent: Thursday, November 8, 2018 10:49 AM
To: tutor at python.org
Subject: Re: [Tutor] Regex for Filesystem path (Asad) 
 


On 08/11/2018 02:55, Asad wrote:

 > Why is it putting \  this breaks the unix path it should be:
 > 
 > /a/b/c/d/test/28163133/22326541   ===> for unix platform logs
 > 
 > \a\b\c\d\test\28163133\22326541  ===> for windows platform logs

Hi,

Maybe pathlib will be of use here:
>>> from pathlib import Path
>>> Path('c:\\beeh/foo\\bar/baz').as_posix()
'c:/beeh/foo/bar/baz'

I was thinking it would also be possible to do (in Windows):
import os.path
os.path.sep = '/'
os.path.normpath('c:\\beeh/foo\\bar/baz')

But alas, this still creates normalized windows-style paths.


More information about the Tutor mailing list