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: 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 Subject: Re: back with more issues Date: Mon, 12 Aug 2013 23:48:12 -0400 Organization: IISS Elusive Unicorn References: <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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Mon, 12 Aug 2013 20:13:31 -0700 (PDT), Kris Mesenbrink 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 "" 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/