Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!novso.com!newsfeed.xs4all.nl!newsfeed1.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '---------': 0.07; 'attribute': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'random': 0.14; 'object).': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:class': 0.16; 'tried:': 0.16; 'values?': 0.16; 'wrote:': 0.18; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'received:comcast.net': 0.24; 'define': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'class': 0.32; 'skip:_ 10': 0.34; 'skip:s 30': 0.35; 'object,': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'simply': 0.61; 'different': 0.65; 'subject:have': 0.80; 'want:': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: I have no class Date: Sat, 22 Nov 2014 22:14:21 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416712474 news.xs4all.nl 2901 [2001:888:2000:d::a6]:39968 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81319 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 -- Ned Batchelder, http://nedbatchelder.com