Fix Python – Set attributes from dictionary in python

Is it possible to create an object from a dictionary in python in such a way that each key is an attribute of that object?
Something like this:
d = { ‘name’: ‘Oscar’, ‘lastName’: ‘Reyes’, ‘age’:32 }

e = Employee(d)
print e.name # Oscar
print e.age + 10 # 42

I think it would be pretty much the inverse of this question: Python dictionary fr….

Fix Python – Check if list of objects contain an object with a certain attribute value

I want to check if my list of objects contain an object with a certain attribute value.
class Test:
def __init__(self, name):
self.name = name

# in main()
l = []
l.append(Test(“t1”))
l.append(Test(“t2”))
l.append(Test(“t2”))

I want a way of checking if list contains an object with name “t1” for example. How can it be done? I found h….

Fix Python – What is the difference between class and instance attributes?

Is there any meaningful distinction between:
class A(object):
foo = 5 # some default value

vs.
class B(object):
def __init__(self, foo=5):
self.foo = foo

If you’re creating a lot of instances, is there any difference in performance or space requirements for the two styles? When you read the code, do you consider the meaning of ….

Fix Python – Extracting an attribute value with beautifulsoup

I am trying to extract the content of a single “value” attribute in a specific “input” tag on a webpage. I use the following code:
import urllib
f = urllib.urlopen(“http://58.68.130.147”)
s = f.read()
f.close()

from BeautifulSoup import BeautifulStoneSoup
soup = BeautifulStoneSoup(s)

inputTag = soup.findAll(attrs={“name” : “stainfo”})

output = ….

Fix Python – How can I create an object and add attributes to it?

I want to create a dynamic object (inside another object) in Python and then add attributes to it.
I tried:
obj = someobject
obj.a = object()
setattr(obj.a, ‘somefield’, ‘somevalue’)

but this didn’t work.
Any ideas?
edit:
I am setting the attributes from a for loop which loops through a list of values, e.g.
params = [‘attr1’, ‘attr2’, ‘attr3’]
ob….