Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #81369

Re: I have no class

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 <davea@davea.name>
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 <davea@davea.name>
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 <e7h27ahs9rjaunu6d91opif62vbr2jefl9@4ax.com> <mailman.16156.1416712474.18130.python-list@python.org> <l9l27alml8scm4dvf29m2vidcudhh6766o@4ax.com> <mailman.16157.1416714761.18130.python-list@python.org> <2qn27adjq412n9nff9kv5jh25d1ekkbncp@4ax.com> <mailman.16160.1416722412.18130.python-list@python.org> <kre37at1cg1m0k3vcav2ekgohfrs5rb465@4ax.com>
In-Reply-To <kre37at1cg1m0k3vcav2ekgohfrs5rb465@4ax.com>
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 <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.16185.1416755794.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


On 11/23/2014 05:52 AM, Seymore4Head wrote:
> On Sun, 23 Nov 2014 17:00:08 +1100, Chris Angelico <rosuav@gmail.com>
> 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

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 21:47 -0500
  Re: I have no class random832@fastmail.us - 2014-11-22 22:08 -0500
    Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 22:16 -0500
  Re: I have no class Rustom Mody <rustompmody@gmail.com> - 2014-11-22 19:09 -0800
    Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 22:18 -0500
  Re: I have no class Ned Batchelder <ned@nedbatchelder.com> - 2014-11-22 22:14 -0500
    Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 22:35 -0500
      Re: I have no class Joel Goldstick <joel.goldstick@gmail.com> - 2014-11-22 22:52 -0500
        Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 23:15 -0500
          Re: I have no class Chris Angelico <rosuav@gmail.com> - 2014-11-23 17:00 +1100
            Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-23 05:52 -0500
              Re: I have no class Dave Angel <davea@davea.name> - 2014-11-23 10:16 -0500
                Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-23 10:54 -0500
                Re: I have no class Dave Angel <davea@davea.name> - 2014-11-23 11:14 -0500
                Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-23 11:49 -0500
                Re: I have no class Chris Angelico <rosuav@gmail.com> - 2014-11-24 03:59 +1100
                Re: I have no class Rustom Mody <rustompmody@gmail.com> - 2014-11-23 09:02 -0800
                Re: I have no class Steven D'Aprano <steve@pearwood.info> - 2014-11-24 04:21 +0000
                Re: I have no class Dave Angel <davea@davea.name> - 2014-11-24 00:11 -0500
                Re: I have no class Chris Angelico <rosuav@gmail.com> - 2014-11-24 16:11 +1100
                Re: I have no class Dan Sommers <dan@tombstonezero.net> - 2014-11-24 13:44 +0000
                Re: I have no class Chris Angelico <rosuav@gmail.com> - 2014-11-25 00:48 +1100
                Re: I have no class Dave Angel <davea@davea.name> - 2014-11-24 00:20 -0500
                Re: I have no class Chris Angelico <rosuav@gmail.com> - 2014-11-24 16:21 +1100
                Re: I have no class Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-24 13:47 -0500
      Re: I have no class Rustom Mody <rustompmody@gmail.com> - 2014-11-22 19:55 -0800
        Re: I have no class Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-11-22 23:19 -0500
        Re: I have no class Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-23 15:35 +0000

csiph-web