data method access

Dennis Lee Bieber wlfraed at ix.netcom.com
Sat Dec 7 15:18:43 EST 2002


Pigio® fed this fish to the penguins on Saturday 07 December 2002 06:35 
am:

> Does it possible to modify variable inside method  __init__ ?
> Example:
> 
> class A:
>    def __init__(test)
>       self.test=test

        Where is "self" coming from? Normally that is the first argument in a 
method.

> 
> I don't write: A.__init__.test=='overvrite'

        First off, A is a class, not an instance. __init__ is called when you 
create an instance of the class.

> In fact when I write A.__init__.__dict__ , answer is {}.
> 
> What can I do to inert inside __init__  another attribute testTwo==
> test?
> 
> 

        I'm not even sure what you are asking, but does this do what you want?


>>> class A:
...     def __init__(self,test):
...             self.test = test
...
>>> anA = A('myTest')
>>> anA
<__main__.A instance at 0x809ea8c>
>>> dir(anA)
['__doc__', '__init__', '__module__', 'test']
>>> anA.test
'myTest'
>>> anotherA = A('Help me...')
>>> anotherA.test
'Help me...'
>>>


-- 
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <




More information about the Python-list mailing list