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


Groups > comp.lang.python > #20496

Re: Wanted: Criticism of code for a Python module, plus a Mac tester

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '"if': 0.04; 'subject:module': 0.04; 'subject:Python': 0.05; 'forth.': 0.07; 'subject:code': 0.07; 'python': 0.08; '__name__': 0.09; 'indexes': 0.09; 'method:': 0.09; 'namespace': 0.09; '2.7': 0.13; 'algorithm': 0.13; 'typing': 0.15; '-tkc': 0.16; 'caveat': 0.16; 'deck': 0.16; 'deck,': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message-id:@tim.thechases.com': 0.16; 'order)': 0.16; 'received:50': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'redundancy': 0.16; 'simulate': 0.16; 'subject:Mac': 0.16; 'linux': 0.17; 'wrote:': 0.18; 'seems': 0.20; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; '(or': 0.22; 'earlier': 0.23; 'assigning': 0.23; 'dictionary': 0.23; 'defined': 0.24; 'otherwise,': 0.25; 'module': 0.26; 'code': 0.26; 'import': 0.27; 'code,': 0.28; 'lists': 0.28; "i'm": 0.28; 'drawing': 0.29; 'odd': 0.29; 'fixed': 0.29; 'seem': 0.29; 'tuples': 0.30; 'usually': 0.31; 'anyone': 0.32; 'there': 0.33; 'header:User-Agent:1': 0.33; 'named': 0.33; 'agree': 0.33; 'it?': 0.33; 'rules': 0.34; 'test': 0.34; 'rather': 0.34; 'running': 0.34; '2.4': 0.34; 'to:addr :python-list': 0.35; '...': 0.35; 'something': 0.35; 'player': 0.35; 'standards': 0.35; 'but': 0.37; 'uses': 0.38; 'some': 0.38; 'should': 0.38; 'prepared': 0.39; "i'd": 0.39; 'point': 0.40; 'might': 0.40; 'to:addr:python.org': 0.40; 'quick': 0.61; 'more': 0.61; 'your': 0.61; 'quality,': 0.63; 'here': 0.64; 'card': 0.65; 'cards': 0.66; 'bridge': 0.80; 'mac.': 0.84; 'yours': 0.86; 'history,': 0.91; 'subject:plus': 0.91; 'rank': 0.96
Date Wed, 15 Feb 2012 18:43:42 -0600
From Tim Chase <python.list@tim.thechases.com>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16
MIME-Version 1.0
To python-list@python.org
Subject Re: Wanted: Criticism of code for a Python module, plus a Mac tester
References <jhhfc6$go$1@news.albasani.net>
In-Reply-To <jhhfc6$go$1@news.albasani.net>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Source
X-Source-Args
X-Source-Dir
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5870.1329354756.27778.python-list@python.org> (permalink)
Lines 77
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1329354756 news.xs4all.nl 6958 [2001:888:2000:d::a6]:55090
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20496

Show key headers only | View raw


On 02/15/12 17:33, HoneyMonster wrote:
> Firstly, is there anyone here who uses Python on a Mac and
> would be prepared to test it? I have tested it on Linux and
> Windows, but don't have access to a Mac.

It works from my quick test of it on my Mac.  The "class 
Player():" and the .format() calls choke on 2.4 (if perhaps for 
some reason you're running it on earlier versions), but 
otherwise, it should be good if you're running 2.7 everywhere.

> Secondly, as a more general point I would welcome comments on
> code quality, adherence to standards and so forth. The code is
> at:


All the .append()s seem a little unpythonic to me.  I'd just set 
it up with

   CONDITIONS = [
     [...],
     ...
     ]

And since you're not modifying it, I'd even use tuples (or named 
tuples):

   CONDITIONS = (
     ("Dealer North", "Neither vulnerable"),
     ...
     )

I'd also take advantage of iterable-unpacking to do something 
like the following in your Player.deal() method:

   for card in cards:
     suit, rank = DECK[card]
     {
      'S': self.spades,
      'D': self.diamonds,
      'C': self.clubs,
      'H': self.hearts,
     }[suit].append(rank)

(that fixed dictionary might even be hoisted out for reuse 
elsewhere).

Additionally, if you import this as a module rather than running 
it directly, there's no "north", "south", ... in your module 
namespace (they're only defined in the "if __name__ ..." section) 
so it will fail.

There are some other structural decisions that I might reconsider 
too:

- just shuffling the deck, rather than shuffling indexes into 
that deck

- there seems to be a lot of redundancy in the drawing code, but 
I'm not sure how I'd reduce that

- assigning to internal rank-named lists seems a little redundant 
to me.  In my (non-bridge) card-playing history, and tinkering 
with small programs like this to simulate card-games, I usually 
just give a player the cards and then leave the sifting/sorting 
to the display algorithm

- I see Ian's email came in as I was typing this and agree with 
his method of defining CONDITIONS with the caveat that it doesn't 
keep the same order as yours (I seem to recall bridge had some 
odd rules about that order)


-tkc



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


Thread

Wanted: Criticism of code for a Python module, plus a Mac tester HoneyMonster <someone@someplace.invalid> - 2012-02-15 23:33 +0000
  Re: Wanted: Criticism of code for a Python module, plus a Mac tester Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-15 17:07 -0700
    Re: Wanted: Criticism of code for a Python module, plus a Mac tester HoneyMonster <someone@someplace.invalid> - 2012-02-16 01:11 +0000
      Re: Wanted: Criticism of code for a Python module, plus a Mac tester Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-15 22:03 -0700
      Re: Wanted: Criticism of code for a Python module, plus a Mac tester Arnaud Delobelle <arnodel@gmail.com> - 2012-02-16 07:59 +0000
  Re: Wanted: Criticism of code for a Python module, plus a Mac tester Tim Chase <python.list@tim.thechases.com> - 2012-02-15 18:43 -0600

csiph-web