| |
comp.lang.python |
--- Paul McGuire <pt...@austin.rr.com> wrote: I'm thinking you could actually have a progression > > > class ShoppingCart: > If you want to nitpick, I'd rather go after the > MAX_ITEMS_FOR_EXPRESS_LANE = 10 > or call it "can_use_express_lane" if you must. Here's my challenge to whoever wants to take it--write The tutorial has this example, which is useful for class MyClass: It also has a ComplexNumber class, but I don't want to It does have this idiom, which I think is worth class Employee: john = Employee() # Create an empty employee record # Fill the fields of the record ___________________________________________________________________________ _________Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more.
> soon as I get a
> breathing space, I'm going to add a "10 Little
> Parsers" page to the
> pyparsing wiki!
from a 1 line program up to a 50-line program. The
number 50 is kind of arbitrary, but my gut says that
by a 50-line program, you will have demonstrated
almost every useful concept.
> > > 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()
> one-liner methods with
> the body on the same line as the def statement.
> def canUseExpressLane(self):
> return (len(self.items) <=
> MAX_ITEMS_FOR_EXPRESS_LANE)
to show, versus a weakish class that just encapulates
a list.
(or find) a program with 20 or fewer lines that
sufficiently motivates the need for classes, has
decent Python style, and is newbie friendly.
demonstrating the syntax of classes, but it doesn't
actually do anything interesting:
"A simple example class"
i = 12345
def f(self):
return 'hello world'
scare away mathphobes.
putting somewhere into the progression.
pass
john.name = 'John Doe'
john.dept = 'computer lab'
john.salary = 1000
http://mobile.yahoo.com/go?refer=1GNXIC