Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4.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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '---------': 0.07; 'attribute': 0.07; '22,': 0.09; 'broke': 0.09; 'cc:addr:python- list': 0.11; 'def': 0.12; 'random': 0.14; '>>on': 0.16; 'dictionary,': 0.16; 'object).': 0.16; 'output?': 0.16; 'subject:class': 0.16; 'tried:': 0.16; 'values?': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'trying': 0.19; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'define': 0.26; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'too.': 0.31; 'class': 0.32; 'url:python': 0.33; 'skip:_ 10': 0.34; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'object,': 0.36; 'skip:> 10': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'nov': 0.38; 'pm,': 0.38; 'url:mail': 0.40; 'how': 0.40; 'simply': 0.61; 'show': 0.63; 'different': 0.65; 'skip:1 20': 0.65; 'subject:have': 0.80; 'batchelder': 0.84; 'want:': 0.84; 'joel': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=sOCkZszZ3weN9aV9/H5rG4hgAKgvnL2eRa6lR51fq08=; b=Aze4s+pa2+RPumczcoYM/4Ho9GeI8M+4Qgr2wnA+6IMOByn3U+1AvRyflIVccK3xC7 eIaOLOFNB9wUqmYxB3+QTr1Il+nqJyVstG5lxjiJY7q8DczNL5nowQKsl4E2dinNrVxL sYvj29c2NbC+FM1GHvJL762YuAK9PdmEXMLI2nowLb4dph+CTPnrY9CUO1vQz0WUtrzq etIlc+aLrBeo5DENdIKmCHWe2Vkv43CA4ocRfWLaC4CJr14aiDb8zAKsSTvo+YZIF+wM DiF8wLcNBoKnKsuBm7pELLoV/LyLvl6Ehx6dZApuJBBzT3U6Pz40xrGelw8r8dNPW5j3 bHbg== MIME-Version: 1.0 X-Received: by 10.224.4.197 with SMTP id 5mr19317312qas.74.1416714753212; Sat, 22 Nov 2014 19:52:33 -0800 (PST) In-Reply-To: References: Date: Sat, 22 Nov 2014 22:52:33 -0500 Subject: Re: I have no class From: Joel Goldstick Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 57 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416714761 news.xs4all.nl 2906 [2001:888:2000:d::a6]:50902 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 802857200 X-Received-Bytes: 4950 Xref: csiph.com comp.lang.python:81323 On Sat, Nov 22, 2014 at 10:35 PM, Seymore4Head wrote: > On Sat, 22 Nov 2014 22:14:21 -0500, Ned Batchelder > wrote: > >>On 11/22/14 9:47 PM, Seymore4Head wrote: >>> What do I need to do to make a and b have different values? >>> import random >>> class RPS: >>> throw=random.randrange(3) >>> a=RPS >>> b=RPS >> >>This simply makes a and b into other names for the class RPS. To >>instantiate a class to make an object, you have to call it: >> >> a = RPS() >> b = RPS() >> >>> --------- >>> I tried: >>> >>> class RPS: >>> def __init__(self): >>> self.throw=random.randrange(3) >>> >>> AttributeError: type object 'RPS' has no attribute 'throw' >> >>This is the right way to define the class (almost: in Py 2, you should >>derive from object). Once you make an object from it, you will have what >>you want: >> >> class RPS(object): >> def __init__(self): >> self.throw = random.randrange(3) >> >> a = RPS() >> b = RPS() >> print a.throw >> print b.throw > > Now I am trying to add a dictionary, but it is broke too. > > How do I fix: > class RPS: > key={0:"rock", 1:"paper",2:"scissors"}; > def __init__(self): > self.throw=random.randrange(3) > self.key=key[self.throw] > -- > https://mail.python.org/mailman/listinfo/python-list can you please show traceback and output? -- Joel Goldstick http://joelgoldstick.com