On 10/4/05, Andrew P <[EMAIL PROTECTED]> wrote:
Oops, Paul is probably right.  I thought urllib2 opened local files in the absence of an identifier like "http://".  Bad assumption on my part.  I remembered that behavior from somewhere else, maybe urllib.

The following function could be useful here - I got it from Dive Into Python - http://diveintopython.org/scripts_and_streams/index.html#kgp.openanything

It tries to open a file with urllib, and if that fails it uses open():
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))



Olly
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to