I have a class that needs access to urllib2, the trivial example for me is:
class foo(object):
myStringHTML = urllib2.urlopen("http://www.google.com").read()
How should I structure my code to include urllib2? In general, I want to store foo in a utility module with a number of other classes, and be able to import foo by itself from the module:
from utilpackage import foo
Is the correct style to put the import inside the class? This seems strange to me, but it works....
class import_u2_in_foo(object):
import urllib2
myStringHtml = urllib2.urlopen("http://www.google.com").read()
Or should I move foo into another package so I always use
import foo
# then foo.py contains
import urllib2
class foo(object):
myStringHtml = urllib2.urlopen("http://www.google.com").read()
How should I structure my code here to be the most pythonic :)?