中国开发网: 论坛: 程序员情感CBD: 贴子 334542
leejd
def openAnything(source):
# try to open with urllib (if source is http, ftp, or file URL)
import urllib
try:
return urllib.urlopen(source)
except (IOError, OSError):
pass

# try to open with native open function (if source is pathname)
try:
return open(source)
except (IOError, OSError):
pass

# treat source as string
import StringIO
return StringIO.StringIO(str(source))

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录