| |
comp.lang.python |
--- Steven Bethard <steven.beth...@gmail.com> wrote: > http://www.python.org/dev/peps/pep-0008/ > I think boughtItems() is probably not a good example > def select_items(self, prefix): Although I didn't call it out in the email, I tried to Did I miss any basic concepts in the first 10 ___________________________________________________________________________ _________Yahoo! oneSearch: Finally, mobile search
> somewhere so that we
> can link to it more easily? Maybe something like:
> Though the code should probably follow PEP 8
> guidelines, e.g.
> under_scores instead of camelCase for object and
> method names:
> </nitpick>
> > 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()
> 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::
> return [item for item in self.items if
> item.startswith(prefix)]
useful class in less than 10 lines of code. Can
somebody else give it a try?
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.
programs? Maybe an 8-liner could demonstrate command
line arguments?
that gives answers, not web links.
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC