How to choose object from list and print its name
<p>I have class Something with few objects:</p>

<pre><code>class Something():
def __init__(self,  name, attr1, attr2):
    self.name= name
    self.attr1= attr1
    self.attr2= attr2

def getName(self):
    return self.name

Obj1=Something('Name1',  'bla bla1',  'bla bla2') 
Obj2=Something('Name2',  'bla bla3',  'bla bla4')
</code></pre>

<p>Those objects are stored in list:</p>

<pre><code>objects = [Obj1, Obj2]
</code></pre>

<p>I want to select object from the printed list and then (if object is on the list) print its name.
So far I wrote code below, but it doesn't work. with error (AttributeError: 'str' object has no attribute 'getNazwa')</p>

<pre><code>print('Select object from list: ', objects)
y=raw_input('enter the name of the object')

for i in objects:
    if y == i:
        print "Name: " + i.getName()
</code></pre>

<p>When print list it's someting like that:</p>

<pre><code>('Select object fromfrom list: ', [&lt;__main__.Something instance at 0x024FB440&gt;, &lt;__main__.Something instance at 0x024FB490&gt;])
</code></pre>

<p>How to convert it into print objects name?</p>

<p>I guess that solution isn't rocket science for You Guys, so someone will help me ;)</p>

<p>Thing is that you compare string to an object here:</p>

<pre><code>if y == i:
</code></pre>

<p>so you should either look at <code>__eq__</code> method of your class, or compare input string with obj name like:</p>

<pre><code>if y == i.getName()
</code></pre>

python class object