I have a container class for urls and their headers, Resource:
class Resource(object):
def __init__(self, url, headers):
self.url = url
self.content-length = headers['content-length']
self.content-type = headers['content-type']
# etc....
The headers argument to the __init__ method expects a dict returned from the getinfo() method of urllib2.urlopen(). I thought this would be a more readable way of packaging up the resource url and headers. Typing self.someheader = headers['someheader'] over and over made me wonder if there's some way to automate creating variables from dictionary keys like this. Is this possible?