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


Groups > comp.lang.python > #52438

Re: back with more issues

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: back with more issues
Date 2013-08-12 23:48 -0400
Organization IISS Elusive Unicorn
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.520.1376365707.1251.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, 12 Aug 2013 20:13:31 -0700 (PDT), Kris Mesenbrink
<krismesenbrink@gmail.com> declaimed the following:

>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():
>    hp = 10
>    def __init__(self, patt):
>        self.att = random.randint(0,5)
>
>
>
>while Player.hp == 10:
>    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.

1)	You fail to create an INSTANCE of a Player...

2)	You set a classwide (ie, ALL instances will have the value) "hp" to a
value of 10

3)	You then loop AS LONG AS the classwide value is 10 (ie; forever)

4)	 You are printing a reference to the __init__ method of the class

5)	 You defined __init__ to take some argument, which you need to pass to
the instance creation


	__init__ is called when you create an instance of the class... that is:

instance = Player()

	Unless you do something IN the __init__ method to change self.hp the
loop will never end.


class Player(object):	#I'm still in Python 2.x, so inheriting from object
						#is needed to get a "new-style" class

	def __init__(self, patt):
		self.hp =  random.randint(0,11)
		self.patt = patt		#no idea what you  intend to do with this

while True:
	aplayer = Player("Junk")	#"Junk" will be bound to self.patt
								#aplayer is an instance of Player with
								#a random hp value
	print aplayer.hp
	if aplayer.hp == 10: break

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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