python - urllib2.urlopen a local file, cross platform -
i'm trying open local file using urllib2
, have following code:
r = urllib2.urlopen('file://' + some_path)
while works on unix, not work on windows because of //
. pythonic way have work cross-platform?
use urllib.pathname2url
:
>>> import urllib >>> 'file:' + urllib.pathname2url(r'c:\path\to\something') 'file:///c:/path/to/something'
Comments
Post a Comment