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

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -