Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52436

Re: back with more issues

Date 2013-08-13 04:31 +0100
From MRAB <python@mrabarnett.plus.com>
Subject Re: back with more issues
References <cc701481-0ecd-411b-8473-0596b4252949@googlegroups.com> <mailman.493.1376286900.1251.python-list@python.org> <kuat2n$msi$1@dont-email.me> <mailman.509.1376337204.1251.python-list@python.org> <88f95aab-0274-48ee-a68a-14a8c3b36e9c@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.518.1376364680.1251.python-list@python.org> (permalink)

Show all headers | View raw


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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

back with more issues Kris Mesenbrink <krismesenbrink@gmail.com> - 2013-08-11 20:33 -0700
  Re: back with more issues Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-12 00:21 -0400
    Re: back with more issues Kris Mesenbrink <krismesenbrink@gmail.com> - 2013-08-11 21:35 -0700
      Re: back with more issues Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-12 00:51 -0400
  Re: back with more issues Dave Angel <davea@davea.name> - 2013-08-12 05:54 +0000
    Re: back with more issues Kris Mesenbrink <krismesenbrink@gmail.com> - 2013-08-11 23:31 -0700
      Re: back with more issues Kris Mesenbrink <krismesenbrink@gmail.com> - 2013-08-11 23:57 -0700
      Re: back with more issues Dave Angel <davea@davea.name> - 2013-08-12 07:11 +0000
    Re: back with more issues Rotwang <sg552@hotmail.co.uk> - 2013-08-12 15:56 +0100
      Re: back with more issues random832@fastmail.us - 2013-08-12 15:46 -0400
        Re: back with more issues Kris Mesenbrink <krismesenbrink@gmail.com> - 2013-08-12 20:13 -0700
          Re: back with more issues MRAB <python@mrabarnett.plus.com> - 2013-08-13 04:31 +0100
          Re: back with more issues Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-12 23:48 -0400
          Re: back with more issues Steven D'Aprano <steve@pearwood.info> - 2013-08-13 06:22 +0000

csiph-web