Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52438
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; '__init__': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'works.': 0.09; 'python': 0.11; 'def': 0.12; 'random': 0.14; '#no': 0.16; '>the': 0.16; 'argument,': 0.16; 'kris': 0.16; 'message-id:@4ax.com': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'repetition': 0.16; 'true:': 0.16; 'working.': 0.19; 'seems': 0.21; 'aug': 0.22; 'print': 0.22; 'url:home': 0.24; 'mon,': 0.24; 'player': 0.26; 'pass': 0.26; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'idea': 0.28; "doesn't": 0.30; 'statement': 0.30; 'class': 0.32; 'there.': 0.32; 'sense': 0.34; 'skip:_ 10': 0.34; 'subject:with': 0.35; 'classes': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'crazy': 0.36; 'instances': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'needed': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'subject:back': 0.60; 'break': 0.61; 'numbers': 0.61; 'subject:more': 0.64; 'between': 0.67; '10:': 0.84; 'end.': 0.84; 'frustrating': 0.84; 'received:108': 0.93; '2013': 0.98 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
| Subject | Re: back with more issues |
| Date | Mon, 12 Aug 2013 23:48:12 -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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | adsl-108-68-178-249.dsl.klmzmi.sbcglobal.net |
| X-Newsreader | Forte Agent 6.00/32.1186 |
| X-No-Archive | YES |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.520.1376365707.1251.python-list@python.org> (permalink) |
| Lines | 59 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1376365707 news.xs4all.nl 15898 [2001:888:2000:d::a6]:48415 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:52438 |
Show key headers only | 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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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