back with more issues

MRAB python at mrabarnett.plus.com
Mon Aug 12 23:31:15 EDT 2013


On 13/08/2013 04:13, Kris Mesenbrink wrote:
> the Classes and __init__ still don't make much sense actually. i have tried and tried again to make it generate numbers between 0 and 5 in a while statement but it just doesn't seem to be working.
>
> import random
>
>
> class Player():

This sets an attribute of the class:

>      hp = 10

This method will be called to initialise an instance of the class when
one is created:

>      def __init__(self, patt):

This sets an attribute of the instance:

>          self.att = random.randint(0,5)
>
>
>
> while Player.hp == 10:

This prints the __init__ method of the class:

>      print (Player.__init__)
>
> atm it seems to be printing "<function Player.__init__ at 0x0000000002954EA0>" over and over again, i don't mind the repetition but from my understanding there should be numbers there. numbers that change. crazy frustrating that i just don't understand how this works.
>
At no point does it create an instance of the class, so the __init__
method is never called.

You can't return anything from the __init__ method because it's called
just to initialise the instance.




More information about the Python-list mailing list