Ah, I mistook you for someone who gives a shit.
- You DID see my post on comp.lang.python and
deliberately ignored it.
- You then lied and claimed there was no discussion.
- You then lied and claimed my example merely
duplicated other examples.
- You claimed to be offended by my characteriz
And while I'm at it...
Although Guido's tutorial was a great place to start when I first came
to python I would have learned more and faster had SimplePrograms
existed. My only complaint with the python documentation is the dearth
of examples. The PHP documentation is chock full.
Steve,
You int
*** New Thread
#5 has been bothering me.
def greet(name):
print 'hello', name
greet('Jack')
greet('Jill')
greet('Bob')
Using greet() three times is cheating and doesn't teach much and
doesn't have any real world use that #1 can't fulfill.
I offer this replacement:
def greet(name):
"""
Steve Howell <[EMAIL PROTECTED]> writes:
> The BankAccount example is about as small of a "complete" class
> example that I could come up with, even though it's "complete" only
> a basic level. It would be good to have a larger class example
> that fleshes out the concept a bit more, even if
--- Pete Forman <[EMAIL PROTECTED]> wrote:
>
> An empty list raises an IndexError, a non-iterable
> raises TypeError.
> This is correct behavior IMHO, there is nothing to
> fix. Median should
> return an element (or average of two) from its input
> and if that is
> not meaningful returning None
Steve Howell <[EMAIL PROTECTED]> writes:
>3) The median example raises the question of what
> would happen with an empty list. I don't think it's
> important to cover that case in the simple example
> (it's really the responsibility of the caller IMO not
> to call median with nonsense ar
--- Pete Forman <[EMAIL PROTECTED]> wrote:
> Steve Howell <[EMAIL PROTECTED]> writes:
>
> > Feel free to change the page as you see fit,
> although thanks for
> > discussing it here first.
>
> Done. I've moved classes up as unittest depends on
> it.
>
> The changes that I made to classes we
Steve Howell <[EMAIL PROTECTED]> writes:
> Feel free to change the page as you see fit, although thanks for
> discussing it here first.
Done. I've moved classes up as unittest depends on it.
The changes that I made to classes were:
1) Use new style class.
2) Demonstrate Pythonic use of attri
--- Pete Forman <[EMAIL PROTECTED]> wrote:
> Steve Howell <[EMAIL PROTECTED]> writes:
>
> >> 2) assert is not the simplest example of doctest.
>
> >> The style should be
> >>
> >> >>> add_money([0.13, 0.02])
> >> 0.15
> >> >>> add_money([100.01, 99.99])
> >> 200.0
> >> >>>
Steve Howell <[EMAIL PROTECTED]> writes:
>> 2) assert is not the simplest example of doctest.
>> The style should be
>>
>> >>> add_money([0.13, 0.02])
>> 0.15
>> >>> add_money([100.01, 99.99])
>> 200.0
>> >>> add_money([0, -13.00, 13.00])
>> 0.0
>>
>
> That's not clear
--- Pete Forman <[EMAIL PROTECTED]> wrote:
> André <[EMAIL PROTECTED]> writes:
>
> > Ok, doctest-based version of the Unit test
> example added; so much
> > more Pythonic ;-)
>
> Sorry for being a bit picky but there are a number
> of things that I'm
> unhappy with in that example.
>
Your p
André <[EMAIL PROTECTED]> writes:
> Ok, doctest-based version of the Unit test example added; so much
> more Pythonic ;-)
Sorry for being a bit picky but there are a number of things that I'm
unhappy with in that example.
1) It's the second example with 13 lines. Though I suppose that the
--- Joe Riopel <[EMAIL PROTECTED]> wrote:
> How about this one for recursion and control flow:
>
> >>> def hcd(m,n):
> ... r = m % n
> ... if( r > 0 ):
> ... hcd(n, r)
> ... else:
> ... print "hcd = %d" % (n,)
> ...
> >>> hcd(119, 544)
> hcd = 17
> >>>
>
> It
How about this one for recursion and control flow:
>>> def hcd(m,n):
... r = m % n
... if( r > 0 ):
... hcd(n, r)
... else:
... print "hcd = %d" % (n,)
...
>>> hcd(119, 544)
hcd = 17
>>>
It calculates the highest common denominator for m and n. Plus it's E1
in
--- rzed <[EMAIL PROTECTED]> wrote:
> Hm
>
> ... and so on.
>
> In much of Python's documentation, and in this case,
> an occasional
> working example of use would go FAR in aiding
> understanding of the
> underlying concept.
>
I agree with your sentiment 100%. Feel free to change
t
--- Steven Bethard <[EMAIL PROTECTED]> wrote:
> > How about including a driver?
>
> Yes, absolutely a good idea. Fortunately, the other
> Steve borrowed the
> time machine already and added this to the end::
>
> for p in iter_primes():
> if p > 1000: break
> print p
>
rzed wrote:
> Steven Bethard <[EMAIL PROTECTED]> wrote in
>> def iter_primes():
>> # an iterator of all numbers between 2 and +infinity
>> numbers = itertools.count(2)
>>
>> # generate primes forever
>> while True
>>
>> # generate the first number from the iterator,
>>
Steven Bethard <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]:
> Steve Howell wrote:
>> --- George Sakkis <[EMAIL PROTECTED]> wrote:
>>> from itertools import count, ifilter
>>> def sieve():
>>> seq = count(2)
>>> while True:
>>> p = seq.next()
>>> seq = ifilter(p.__r
--- Steven Bethard <[EMAIL PROTECTED]> wrote:
unit.text)
>
> I posted a slight variant of this, trimmed down a
> bit to 21 lines.
>
Thanks, I think this will be a very useful example.
Pinpoint custome
Rob Wolfe wrote:
> # HTML page
> dinner_recipe = '''
> Recipe
>
> amtunititem
> 24slicesbaguette
> 2+tbspolive_oil
> 1cuptomatoes
> 1-2tbspgarlic
> 1/2cupParmesan
> 1jarpesto
>
> '''
>
> # program
> import xml.etree.ElementTree as etree
> tree = etree.fromstring(dinner_recipe)
>
> #import Eleme
--- Steven Bethard <[EMAIL PROTECTED]> wrote:
> Rob Wolfe wrote:
> > Steve Howell wrote:
> >
> >> I suggested earlier that maybe we post multiple
> >> solutions. That makes me a little nervous, to
> the
> >> extent that it shows that the Python community
> has a
> >> hard time coming to consens
# writing/reading CSV files, tuple-unpacking, cmp() built-in
import csv
writer = csv.writer(open('stocks.csv', 'wb'))
writer.writerows([
('GOOG', 'Google, Inc.', 505.24, 0.47, 0.09),
('YHOO', 'Yahoo! Inc.', 27.38, 0.33, 1.22),
('CNET', 'CNET Networks, Inc.', 8.62, -0.13, -1.49)
])
sto
Rob Wolfe wrote:
> Steven Bethard <[EMAIL PROTECTED]> writes:
>
>>> I vote for example with ElementTree (without xpath)
>>> with a mention of using ElementSoup for invalid HTML.
>> Sounds good to me. Maybe something like::
>>
>> import xml.etree.ElementTree as etree
>> dinner_recipe = '''
>>
>>
Steven Bethard <[EMAIL PROTECTED]> writes:
>> I vote for example with ElementTree (without xpath)
>> with a mention of using ElementSoup for invalid HTML.
>
> Sounds good to me. Maybe something like::
>
> import xml.etree.ElementTree as etree
> dinner_recipe = '''
>
> 24slicesbaguette
> 2+tbspol
Rob Wolfe wrote:
> Steve Howell wrote:
>
>> I suggested earlier that maybe we post multiple
>> solutions. That makes me a little nervous, to the
>> extent that it shows that the Python community has a
>> hard time coming to consensus on tools sometimes.
>
> We agree that BeautifulSoup is the bes
Steve Howell wrote:
> I suggested earlier that maybe we post multiple
> solutions. That makes me a little nervous, to the
> extent that it shows that the Python community has a
> hard time coming to consensus on tools sometimes.
We agree that BeautifulSoup is the best for parsing HTML. :)
> Th
--- Steven Bethard <[EMAIL PROTECTED]> wrote:
> Stefan Behnel wrote:
> > Steven Bethard wrote:
> >> If you want to parse invalid HTML, I strongly
> encourage you to look into
> >> BeautifulSoup. Here's the updated code:
> >>
> >> import ElementSoup #
> http://effbot.org/zone/element-soup.htm
Stefan Behnel wrote:
> Steven Bethard wrote:
>> If you want to parse invalid HTML, I strongly encourage you to look into
>> BeautifulSoup. Here's the updated code:
>>
>> import ElementSoup # http://effbot.org/zone/element-soup.htm
>> import cStringIO
>>
>> tree = ElementSoup.parse(cStri
Steven Bethard wrote:
> Rob Wolfe wrote:
>> Steven Bethard <[EMAIL PROTECTED]> writes:
>>> I'd hate to steer a potential new Python developer to a clumsier
>>
>> "clumsier"???
>> Try to parse this with your program:
>>
>> page2 = '''
>> URLs
>>
>>
>> http://domain1/page1";>som
--- Steven Bethard <[EMAIL PROTECTED]> wrote:
> # print the first 100 primes
> for prime in itertools.islice(iter_primes(),
> 100):
> print prime
>
Sure. FWIW, in the example I posted, I kept the
output loop a little more pedestrian (using an
if/break idiom), and I printed pr
--- Steven Bethard <[EMAIL PROTECTED]> wrote:
> On 6/12/07, Steve Howell <[EMAIL PROTECTED]>
> wrote:
> > --- Steven Bethard <[EMAIL PROTECTED]>
> wrote:
> > > import itertools
> > >
> > > def iter_primes():
> > > # an iterator of all numbers between 2 and
> > > +infinity
> > > numbers
Steve Howell wrote:
> --- Steven Bethard <[EMAIL PROTECTED]> wrote:
>> How about we just comment it better?
>>
>> import itertools
>>
>> def iter_primes():
>> # an iterator of all numbers between 2 and +infinity
>> numbers = itertools.count(2)
[snip]
>
> Actually, just one small caveat--
--- I wrote:
> [...] was the final straw in converting
> me from Python to Perl.
Er, Perl to Python.
In looking backwards, I started writing backwards.
And no, I'm not ever going back to Perl...
Boa
--- Steven Bethard <[EMAIL PROTECTED]> wrote:
> Steve Howell wrote:
> > --- George Sakkis <[EMAIL PROTECTED]> wrote:
> >> from itertools import count, ifilter
> >> def sieve():
> >> seq = count(2)
> >> while True:
> >> p = seq.next()
> >> seq = ifilter(p.__rmod__, seq)
> >
--- Steven Bethard <[EMAIL PROTECTED]> wrote:
> Steve Howell wrote:
> > --- George Sakkis <[EMAIL PROTECTED]> wrote:
> >> from itertools import count, ifilter
> >> def sieve():
> >> seq = count(2)
> >> while True:
> >> p = seq.next()
> >> seq = ifilter(p.__rmod__, seq)
> >
Steve Howell wrote:
> --- George Sakkis <[EMAIL PROTECTED]> wrote:
>> from itertools import count, ifilter
>> def sieve():
>> seq = count(2)
>> while True:
>> p = seq.next()
>> seq = ifilter(p.__rmod__, seq)
>> yield p
[snip]
> Is there a way to broaden the problem s
--- Rob Wolfe <[EMAIL PROTECTED]> wrote:
>
> What about simple HTML parsing? As a matter of fact
> this is not
> language concept, but shows the power of Python
> standard library.
> Besides, that's very popular problem among newbies.
I totally agree with the relevance of this example.
FWIW it
--- George Sakkis <[EMAIL PROTECTED]> wrote:
>
> from itertools import count, ifilter
> def sieve():
> seq = count(2)
> while True:
> p = seq.next()
> seq = ifilter(p.__rmod__, seq)
> yield p
>
>
> I suspect that it violates your second rule though
> :)
>
I'm g
On Jun 11, 5:56 pm, Steve Howell <[EMAIL PROTECTED]> wrote:
> Hi, I'm offering a challenge to extend the following
> page by one good example:
>
> http://wiki.python.org/moin/SimplePrograms
>
> Right now the page starts off with 15 examples that
> cover lots of ground in Python, but they're still
--- Rob Wolfe <[EMAIL PROTECTED]> wrote:
> Steven Bethard <[EMAIL PROTECTED]> writes:
>
> > I'd hate to steer a potential new Python developer
> > to a clumsier [...]
>
> [...]
> But as far as HTML (not XML) is concerned this is
> not very realistic solution.
>
I think both posted examples wou
Steven Bethard wrote:
> Rob Wolfe wrote:
>> Steven Bethard <[EMAIL PROTECTED]> writes:
>>> I'd hate to steer a potential new Python developer to a clumsier
>>
>> "clumsier"???
>> Try to parse this with your program:
>>
>> page2 = '''
>> URLs
>>
>>
>> http://domain1/page1";>som
Rob Wolfe wrote:
> Steven Bethard <[EMAIL PROTECTED]> writes:
>> I'd hate to steer a potential new Python developer to a clumsier
>
> "clumsier"???
> Try to parse this with your program:
>
> page2 = '''
> URLs
>
>
> http://domain1/page1";>some page1
> http://domain2/pag
Steven Bethard <[EMAIL PROTECTED]> writes:
> I'd hate to steer a potential new Python developer to a clumsier
"clumsier"???
Try to parse this with your program:
page2 = '''
URLs
http://domain1/page1";>some page1
http://domain2/page2";>some page2
'''
> libra
Rob Wolfe wrote:
> Steve Howell wrote:
>> Hi, I'm offering a challenge to extend the following
>> page by one good example:
>>
>> http://wiki.python.org/moin/SimplePrograms
>
> What about simple HTML parsing? As a matter of fact this is not
> language concept, but shows the power of Python standar
Steve Howell wrote:
> Hi, I'm offering a challenge to extend the following
> page by one good example:
>
> http://wiki.python.org/moin/SimplePrograms
What about simple HTML parsing? As a matter of fact this is not
language concept, but shows the power of Python standard library.
Besides, that's v
On Jun 11, 4:56?pm, Steve Howell <[EMAIL PROTECTED]> wrote:
> Hi, I'm offering a challenge to extend the following
> page by one good example:
>
> http://wiki.python.org/moin/SimplePrograms
>
> Right now the page starts off with 15 examples that
> cover lots of ground in Python, but they're still
>
--- John Machin <[EMAIL PROTECTED]> wrote:
> On Jun 12, 9:16 am, Steve Howell
> <[EMAIL PROTECTED]> wrote:
>
> >
> > One more suggestion--maybe it could exercise a
> little
> > more of the CVS module, i.e. have something in the
> > data that would trip up the ','.split() approach?
>
> The what
On Jun 12, 9:16 am, Steve Howell <[EMAIL PROTECTED]> wrote:
>
> One more suggestion--maybe it could exercise a little
> more of the CVS module, i.e. have something in the
> data that would trip up the ','.split() approach?
The what approach?? Do you mean blah.split(',') ??
Perhaps like an exampl
On Jun 12, 8:51 am, infidel <[EMAIL PROTECTED]> wrote:
> # reading CSV files, tuple-unpacking
> import csv
>
> #pacific.csv contains:
> #1,CA,California
> #2,AK,Alaska
> #3,OR,Oregon
> #4,WA,Washington
> #5,HI,Hawaii
>
> reader = csv.reader(open('pacific.csv'))
For generality and portability, this
--- infidel <[EMAIL PROTECTED]> wrote:
> # reading CSV files, tuple-unpacking
> import csv
>
> #pacific.csv contains:
> #1,CA,California
> #2,AK,Alaska
> #3,OR,Oregon
> #4,WA,Washington
> #5,HI,Hawaii
>
> reader = csv.reader(open('pacific.csv'))
> for id, abbr, name in reader:
> print '%s i
On Jun 11, 6:56 pm, Steve Howell <[EMAIL PROTECTED]> wrote:
> Hi, I'm offering a challenge to extend the following
> page by one good example:
>
> http://wiki.python.org/moin/SimplePrograms
>
> Right now the page starts off with 15 examples that
> cover lots of ground in Python, but they're still
>
# reading CSV files, tuple-unpacking
import csv
#pacific.csv contains:
#1,CA,California
#2,AK,Alaska
#3,OR,Oregon
#4,WA,Washington
#5,HI,Hawaii
reader = csv.reader(open('pacific.csv'))
for id, abbr, name in reader:
print '%s is abbreviated: "%s"' % (name, abbr)
--
http://mail.python.org/mai
52 matches
Mail list logo