Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'attribute': 0.07; 'class,': 0.07; 'defaults': 0.07; 'indices': 0.07; 'modify': 0.07; 'def': 0.12; 'random': 0.14; 'dictionary.': 0.16; 'once.': 0.16; 'sequential': 0.16; 'subject:class': 0.16; 'such,': 0.16; 'throw': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'module': 0.19; '(but': 0.19; "python's": 0.19; 'rules': 0.22; 'saying': 0.22; 'header:User- Agent:1': 0.23; 'class.': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; 'class': 0.32; 'another': 0.32; 'skip:_ 10': 0.34; 'could': 0.34; 'skip:s 30': 0.35; 'but': 0.35; 'useful': 0.36; 'thanks': 0.36; 'list': 0.37; 'thank': 0.38; 'problems': 0.38; 'convention': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'referred': 0.60; 'first': 0.61; 'name': 0.63; 'skip:1 20': 0.65; 'received:74.208': 0.68; 'helping': 0.70; 'wish': 0.70; 'subject:have': 0.80; 'all!': 0.84; 'confusing': 0.84 Date: Sun, 23 Nov 2014 10:16:28 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: I have no class References: <2qn27adjq412n9nff9kv5jh25d1ekkbncp@4ax.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:GC7RHmbUUAFpZfO09EYpxT+YU6TBror3aU0GwulRvFB i2X6mBt+Ym5FukF3DsB+lO5VnlLf4LivpMWY6qOcIb9sDzMb0F 5373iDmk91h+bedhidGn0zi2/achWEy6Z3kud4WVlqJJk9IKyJ 3RnU519BG0VF289yEgVM6YL0J6sKnzUwZ7JC2kN5Wk3I/97Avg y3g7Ue7K48D44UK1Cr78djMQ9i4ob7hFXFxE0eU4m5SCwHFzHL riqR8O5wPWRxxxiePnK/tU30ZfTTFWYk/MG9+oqsD8JDLwEpMV /q7jwGil+aVBelCDdBiUbOOzpgJjCErjgoSFDr78N5jLxWuE5N x7XkR3gGnD4RDp5g/5V8= X-UI-Out-Filterresults: notjunk:1; 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416755794 news.xs4all.nl 2845 [2001:888:2000:d::a6]:60020 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81369 On 11/23/2014 05:52 AM, Seymore4Head wrote: > On Sun, 23 Nov 2014 17:00:08 +1100, Chris Angelico > wrote: > >> >> 1) Python's namespacing rules mean that 'key' is a part of the RPS >> class, and can be referred to as 'self.key' or as 'RPS.key' >> 2) Use of 'self.key' for the textual form of the throw is shadowing >> the first of those reference names (but it's a poor name anyway) >> 3) A list would work just as well as a dictionary here, since your >> indices are sequential and start from zero >> 4) There's another function in the random module which can do both of >> your steps at once. >> >> Thank you for helping us help you help us all! >> >> ChrisA > > I wish I could explain my problems so precisely. I will try to do > better in the future. > Thanks > > I will also try this using a list instead of a dictionary. > And please avoid the shadowing. It's confusing whenever the same name is used for a class attribute and an instance attribute of the same class. it can be useful for defaults and such, but not here. class RPS: KEY_TABLE={0:"rock", 1:"paper",2:"scissors"}; or KEY_TABLE= ("rock", "paper", "scissors") def __init__(self): self.throw=random.randrange(3) self.key=RPS.KEY_TABLE[self.throw] Note I also capitalized the tuple name, which is a convention saying we don't intend to modify it. -- DaveA