fab*_*789 4 python cross-platform urllib2
我正在尝试使用打开本地文件,urllib2并具有以下代码:
r = urllib2.urlopen('file://' + some_path)
Run Code Online (Sandbox Code Playgroud)
尽管此功能在Unix上有效,但由于,它在Windows上无效//。跨平台工作的最Python方式是什么?
>>> import urllib
>>> 'file:' + urllib.pathname2url(r'c:\path\to\something')
'file:///C:/path/to/something'
Run Code Online (Sandbox Code Playgroud)