Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion ten small Python programs

View parsed - Show only message text

Path: g2news1.google.com!news4.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!62.216.30.27.MISMATCH!newsgate.cistron.nl!transit.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path: <showel...@yahoo.com>
X-Original-To: python-l...@python.org
Delivered-To: python-l...@bag.python.org
X-Spam-Status: OK 0.000
X-YMail-OSG: gpaKhtUVM1mSRFR9Z_jyxoP3PUe0S5OQYy_5kpKYgo4lW5YuOGG89m.lkD9bPdp7H1Co3BEL_09a29X7_u2jzUqZhdPBvPoOrplxYjslSlbnBJgXemE-
Date: Sat, 26 May 2007 13:05:02 -0700 (PDT)
From: Steve Howell <showel...@yahoo.com>
Subject: Re: ten small Python programs
To: Steven Bethard <steven.beth...@gmail.com>, python-l...@python.org
In-Reply-To: <mcidnYViZIlYEcXbnZ2dnUVZ_uKknZ2d@comcast.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-BeenThere: python-l...@python.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: General discussion list for the Python programming language
	<python-list.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/listinfo/python-list>,
	<mailto:python-list-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-list>
List-Post: <mailto:python-l...@python.org>
List-Help: <mailto:python-list-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-list>,
	<mailto:python-list-requ...@python.org?subject=subscribe>
Newsgroups: comp.lang.python
Message-ID: <mailman.8220.1180209928.32031.python-list@python.org>
Lines: 69
NNTP-Posting-Host: 194.109.207.14
X-Trace: 1180209928 news.xs4all.nl 69886 [::ffff:194.109.207.14]:41529
X-Complaints-To: abuse@xs4all.nl


--- Steven Bethard <steven.beth...@gmail.com> wrote:
> Very cool! Do you mind putting this up on the Wiki
> somewhere so that we 
> can link to it more easily? Maybe something like:
> 
>      http://wiki.python.org/moin/SimplePrograms
>

Done.
 
> <nitpick>
> Though the code should probably follow PEP 8
> guidelines, e.g. 
> under_scores instead of camelCase for object and
> method names:
> 
>      http://www.python.org/dev/peps/pep-0008/
> </nitpick>
> 

I think I fixed them, please see Wiki to verify.


> >     class ShoppingCart:
> >         def __init__(self): self.items = []
> >         def buy(self, item):
> self.items.append(item)
> >         def boughtItems(self): return self.items
> >     myCart = ShoppingCart()
> >     myCart.buy('apple')
> >     myCart.buy('banana')
> >     print myCart.boughtItems()
> 
> I think boughtItems() is probably not a good example
> of Python code 
> since in this case, you should probably just write
> ``my_cart.items``. 
> Maybe it should define ``__len__`` instead? Or maybe
> something like::
> 
>      def select_items(self, prefix):
>          return [item for item in self.items if
> item.startswith(prefix)]
> 

I think the problem here is that it's hard to write a
useful class in less than 10 lines of code.  Can
somebody else give it a try?

Although I didn't call it out in the email, I tried to
make each program progressively one line longer, so if
somebody wants to write, say, an 11-line class
example, then I will try fill in the gap with another
8-liner.

Did I miss any basic concepts in the first 10
programs?  Maybe an 8-liner could demonstrate command
line arguments?






       
____________________________________________________________________________________Yahoo! oneSearch: Finally, mobile search 
that gives answers, not web links. 
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google