lars111 lars111 - 5 months ago 25
Python Question

Python class input argument

I am new to OOP. My idea was to implement the following class:

class name(object, name):
def __init__(self, name):
print name


Then the idea was to create two instances of that class:

person1 = name("jean")
person2 = name("dean")


I know, that is not possible, but how can I pass an input-argument into an instance of a class?

Answer
>>> class name(object):
...     def __init__(self, name):
...         self.name = name
... 
>>> person1 = name("jean")
>>> person2 = name("dean")
>>> person1.name
'jean'
>>> person2.name
'dean'
>>>

Is this what you are looking for?