Look, not to be harsh or anything, but given you previous posts I think you would be better off reading a book or a wiki or even just a tutorial on Python OOP and maybe Python in general. Really.
scru
Posting Virtuoso
1,629 posts since Feb 2007
Reputation Points: 975
Solved Threads: 140
so why doesn't it (the code above) work?
Why shoud it?
Break it thing down to understand what happends.
>>> class my_class:
def __init__ (self):
self.name = ' my name is hi'
>>> a = my_class() #Class instance
>>> print a
<__main__.my_class instance at 0x011E23F0>
>>>
# This only show the class instance and memory location.
# So you see now that your code can not work.
>>> a.name #call __init__(constructor)
' my name is hi'
>>> my_list= ['a','b']
>>> for x in my_list:
print a.name, x
my name is hi a
my name is hi b
This dosent make must sense.
Just one way that give a little more sense.
----------------
my_list= ['a','b']
class my_class:
def __init__ (self, name):
self.name = name
a = my_class('Tom')
for x in my_list:
print 'Hi %s my name is %s' % (a.name, x)
output-->
Hi Tom my name is a
Hi Tom my name is b
----------------
snippsat
Practically a Posting Shark
808 posts since Aug 2008
Reputation Points: 353
Solved Threads: 294