Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
ten small Python programs
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 26 - 44 of 44 - Collapse all  -  Translate all to Translated (View all originals) < Older 
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steve Howell  
View profile  
 More options May 28 2007, 5:00 am
Newsgroups: comp.lang.python
From: Steve Howell <showel...@yahoo.com>
Date: Sun, 27 May 2007 12:00:16 -0700 (PDT)
Local: Mon, May 28 2007 5:00 am
Subject: Re: ten small Python programs

--- Steven Bethard <steven.beth...@gmail.com> wrote:

Maybe this is the first good example that motivates a
hyperlink to alternatives.  Would you accept the idea
that we keep my original example on the SimplePrograms
page, but we link to a UnitTestingPhilosophies page,
and we show your alternative there?  Or vice versa,
show your example on the first page, but then show
mine on the hyperlinked page?

I am in 100% agreement with you that most unit tests
would be completely outside the module, although I
often follow the practice that my modules have a
little "if __main__" section that runs a few simple
unit tests, as sort of a bit of self-documentation.

___________________________________________________________________________ _________Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
http://smallbusiness.yahoo.com/webhosting


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steven Bethard  
View profile  
 More options May 28 2007, 5:01 am
Newsgroups: comp.lang.python
From: Steven Bethard <steven.beth...@gmail.com>
Date: Sun, 27 May 2007 13:01:54 -0600
Local: Mon, May 28 2007 5:01 am
Subject: Re: ten small Python programs

Sure.  Either way is fine.

STeVe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "unit testing" by Steve Howell
Steve Howell  
View profile  
 More options May 28 2007, 5:14 am
Newsgroups: comp.lang.python
From: Steve Howell <showel...@yahoo.com>
Date: Sun, 27 May 2007 12:14:54 -0700 (PDT)
Local: Mon, May 28 2007 5:14 am
Subject: unit testing
--- Steven Bethard <steven.beth...@gmail.com> wrote:

> Have you tried py.test?

>      http://codespeak.net/py/dist/test.html

> I've heard good things about it, but haven't gotten
> around to trying it
> yet. Here's a two-line test suite from the page
> above:

>      def test_answer():
>          assert 42 == 43

Changed the subject line.

Nope, I haven't.  I'm a tremendous advocate of unit
testing, but I've never felt compelled to try out
other libraries, because I work mostly on private code
now, so the
following-standard-practices-to-benefit-from-familiarity
argument doesn't carry much weight with me, and also
because I find it easy enough to do things on a
roll-your-own basis.  YMMV, of course.

I have slowly introduced unit testing into my own work
environment, with some success.  We don't use a 3rd
party testing framework, but here's my roll-your-own
approach:

   1) For flat-out failures, we just fail with a
traceback right away.  We don't bother to capture
stats on how many tests failed.  If one test fails,
that's enough to clue in a developer that he/she broke
something.

   2) We don't use assertions very often, but rather
just diff the output files to the GOLD files.  This
may eventually stop to scale, but it hasn't yet.

   3)We have a little trickery to override imports,
etc., as 99.99% of our code was never written with
unit testing in mind, but I still want to regression
test it.

  4) We have quite a few mock-ish objects, mainly
relating to simulating I/O situations.

___________________________________________________________________________ _________Pinpoint customers who are looking for what you sell.
http://searchmarketing.yahoo.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "ten small Python programs" by Steve Howell
Steve Howell  
View profile  
 More options May 28 2007, 5:17 am
Newsgroups: comp.lang.python
From: Steve Howell <showel...@yahoo.com>
Date: Sun, 27 May 2007 12:17:29 -0700 (PDT)
Local: Mon, May 28 2007 5:17 am
Subject: Re: ten small Python programs

--- Steven Bethard <steven.beth...@gmail.com> wrote:

Ok, for now, I'm taking no action, let's let the unit
testing discussion progress a little.  Despite my
saying early that I don't want to debate it, I do want
to discuss it :), as it is near in dear to my heart.

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Rubin  
View profile  
(1 user)  More options May 28 2007, 6:13 am
Newsgroups: comp.lang.python
From: Paul Rubin <http://phr...@NOSPAM.invalid>
Date: 27 May 2007 13:13:10 -0700
Local: Mon, May 28 2007 6:13 am
Subject: Re: ten small Python programs

Steven Bethard <steven.beth...@gmail.com> writes:
> I think I would rewrite the current unit-testing example to use the
> standard library unittest module::

I think these days we're supposed to like doctest better than unittest.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adonis Vargas  
View profile  
 More options May 28 2007, 8:37 am
Newsgroups: comp.lang.python
From: Adonis Vargas <ado...@REMOVETHISearthlink.net>
Date: Sun, 27 May 2007 22:37:13 GMT
Local: Mon, May 28 2007 8:37 am
Subject: Re: ten small Python programs

Steve Howell wrote:
> I've always thought that the best way to introduce new
> programmers to Python is to show them small code
> examples.  

<snip>

You could try this wiki page:

http://rosettacode.org/wiki/Main_Page

It has a fair amount of Python examples as well as many more other
languages (doing the same algorithm).

Hope this helps.

Adonis


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "unit testing" by Steven Bethard
Steven Bethard  
View profile  
 More options May 28 2007, 9:14 am
Newsgroups: comp.lang.python
From: Steven Bethard <steven.beth...@gmail.com>
Date: Sun, 27 May 2007 17:14:20 -0600
Local: Mon, May 28 2007 9:14 am
Subject: Re: unit testing

My view is generally that if I can get someone else to maintain parts of
my code for me, that's a good thing. ;-)

>    1) For flat-out failures, we just fail with a
> traceback right away.

Looks like that's the -x/--exitfirst option in py.test.

>    2) We don't use assertions very often, but rather
> just diff the output files to the GOLD files.  This
> may eventually stop to scale, but it hasn't yet.

I guess I don't do enough stuff with file input and file output for this
to make sense for me.

>    3)We have a little trickery to override imports,
> etc., as 99.99% of our code was never written with
> unit testing in mind, but I still want to regression
> test it.

>   4) We have quite a few mock-ish objects, mainly
> relating to simulating I/O situations.

You might look into the Python Mock module:

     http://python-mock.sourceforge.net/

STeVe


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options May 28 2007, 9:32 am
Newsgroups: comp.lang.python
From: Steve Howell <showel...@yahoo.com>
Date: Sun, 27 May 2007 16:32:45 -0700 (PDT)
Local: Mon, May 28 2007 9:32 am
Subject: Re: unit testing
Let me preface every reply here by YMMV.  I strongly,
strongly encourage people to tap into the unit testing
community for all tools that are available to them.

Also, let me say that despite any place where Steven
and I disagree about the mechanics of unit testing,
we're in firm agreement that UNIT TESTING IS
IMPORTANT.  And sorry for shouting.  And, really, if
you're not doing automated tests on your application
now, you don't know what you're missing.

--- Steven Bethard <steven.beth...@gmail.com> wrote:

> >    1) For flat-out failures, we just fail with a
> > traceback right away.

> Looks like that's the -x/--exitfirst option in
> py.test.

Yes, but for my purposes, it's even easier to do
absolutely nothing when a test fails, just let it pass
through.

> >    2) We don't use assertions very often, but
> rather
> > just diff the output files to the GOLD files.
> This
> > may eventually stop to scale, but it hasn't yet.

> I guess I don't do enough stuff with file input and
> file output for this
> to make sense for me.

First, I should say that we don't completely ignore
assertion tests, as it's useful for testing truly
functional code, such as something that simply parses
a message.  

But most of our application is I/O driven, and the
actual tricky modules of our application do manage a
conversation between a terminal and a host, and it's
that conversation between the terminal that we want to
proceed in a predictable fashion.

> >   4) We have quite a few mock-ish objects, mainly
> > relating to simulating I/O situations.

> You might look into the Python Mock module:

>      http://python-mock.sourceforge.net/

Again, this is a case, where pardon my arrogance, I
already know how my objects work, so I already know
how to emulate them.  I've read up on mock objects, so
I'm not totally ignoring common wisdom, it's just that
I get it, have a powerful language at my disposal,
etc.  I fully concede that my mock objects might be
missing key features from the Python Mock module, but
I also assert that I can implement pretty robust unit
testing without it.

___________________________________________________________________________ _________Got a little couch potato?
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "ten small Python programs" by DJ Fadereu
DJ Fadereu  
View profile  
 More options May 28 2007, 3:17 pm
Newsgroups: comp.lang.python
From: DJ Fadereu <fade...@gmail.com>
Date: 27 May 2007 22:17:11 -0700
Local: Mon, May 28 2007 3:17 pm
Subject: Re: ten small Python programs

> You could try this wiki page:

> http://rosettacode.org/wiki/Main_Page

> It has a fair amount of Python examples as well as many more other
> languages (doing the same algorithm).

> Hope this helps.

> Adonis

THIS IS GREAT :) Thanx!

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "unit testing" by Nis Jørgensen
Nis Jørgensen  
View profile  
 More options May 28 2007, 6:34 pm
Newsgroups: comp.lang.python
From: Nis Jørgensen <n...@superlativ.dk>
Date: Mon, 28 May 2007 10:34:49 +0200
Local: Mon, May 28 2007 6:34 pm
Subject: Re: unit testing
Steve Howell skrev:

> And, really, if
> you're not doing automated tests on your application
> now, you don't know what you're missing.

Quote of the day, IMO.

Nis


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "ten small Python programs" by Stef Mientki
Stef Mientki  
View profile  
 More options May 29 2007, 1:43 am
Newsgroups: comp.lang.python
From: Stef Mientki <S.Mientki-nos...@mailbox.kun.nl>
Date: Mon, 28 May 2007 17:43:14 +0200
Local: Tues, May 29 2007 1:43 am
Subject: Re: ten small Python programs
Steve Howell wrote:
> I've always thought that the best way to introduce new
> programmers to Python is to show them small code
> examples.  

This is really a nice piece of missing Python.

Sorry I didn't follow this thread accurately,
but have you considered to produce an example environment like in wxPython ?

The wxPython demo program is written as an interactive tutorial,
with a few hundred examples, nicely ordered in groups.
The user can view the demo, the code and the help text.
The user can also change the code and see the results right away.

It would even be nicer, if everybody could drop her/his examples
in a standard way, so they would be automatically incorporated in
something like the wxPython interactive demo.

cheers,
Stef Mientki


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kay Schluehr  
View profile  
 More options May 29 2007, 1:42 am
Newsgroups: comp.lang.python
From: Kay Schluehr <kay.schlu...@gmx.net>
Date: 28 May 2007 08:42:29 -0700
Local: Tues, May 29 2007 1:42 am
Subject: Re: ten small Python programs
Just for the amusement of the audience. The following is a reusable
testscript:

>>> def add_money(amounts):

...     pennies = sum([round(int(amount * 100)) for amount in amounts])
...     return float(pennies / 100.0)
...

>>> add_money([0.13, 0.02]) == 0.15
0.14999999999999999
>>> add_money([0.13, 0.02]) == 0.15
True
>>> assert add_money([0.13, 0.02]) == 0.15
>>> assert add_money([100.01, 99.99]) ==  200
>>> assert add_money([0, -13.00, 13.00]) ==  0

It's just a matter of perspective...

http://fiber-space.de/EasyExtend/doc/consoletest/consoletest.html


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options May 29 2007, 2:35 am
Newsgroups: comp.lang.python
From: Steve Howell <showel...@yahoo.com>
Date: Mon, 28 May 2007 09:35:45 -0700 (PDT)
Local: Tues, May 29 2007 2:35 am
Subject: Re: ten small Python programs

--- Stef Mientki <S.Mientki-nos...@mailbox.kun.nl>
wrote:

> Steve Howell wrote:
> > I've always thought that the best way to introduce
> new
> > programmers to Python is to show them small code
> > examples.  

> This is really a nice piece of missing Python.

Thanks.

> The wxPython demo program is written as an
> interactive tutorial,
> with a few hundred examples, nicely ordered in
> groups.
> The user can view the demo, the code and the help
> text.
> The user can also change the code and see the
> results right away.

Do you have a link?

> It would even be nicer, if everybody could drop
> her/his examples
> in a standard way, so they would be automatically
> incorporated in
> something like the wxPython interactive demo.

Can you elaborate?

___________________________________________________________________________ _________
8:00? 8:25? 8:40? Find a flick in no time
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stef Mientki  
View profile  
 More options May 29 2007, 4:48 am
Newsgroups: comp.lang.python
From: Stef Mientki <S.Mientki-nos...@mailbox.kun.nl>
Date: Mon, 28 May 2007 20:48:53 +0200
Local: Tues, May 29 2007 4:48 am
Subject: Re: ten small Python programs

>> The wxPython demo program is written as an
>> interactive tutorial,
>> with a few hundred examples, nicely ordered in
>> groups.
>> The user can view the demo, the code and the help
>> text.
>> The user can also change the code and see the
>> results right away.

> Do you have a link?

wxPython including demos can be downloaded from

   http://www.wxpython.org

but there's no separate page of the demo,
so I made a few screenshots:

http://oase.uci.kun.nl/~mientki/data_www/pic/jalcc/python/wxpython_ov...

>> It would even be nicer, if everybody could drop
>> her/his examples
>> in a standard way, so they would be automatically
>> incorporated in
>> something like the wxPython interactive demo.

> Can you elaborate?

Well if you see the above demo,
I've the following in mind:
- create a new-demo in a special directory
- add some special keywords in the new-demo, in which treenodes it should popup
- on restart of the demo, the new-demo is added to the tree

cheers,
Stef Mientki


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options May 29 2007, 5:38 am
Newsgroups: comp.lang.python
From: Steve Howell <showel...@yahoo.com>
Date: Mon, 28 May 2007 12:38:04 -0700 (PDT)
Local: Tues, May 29 2007 5:38 am
Subject: Re: ten small Python programs

--- Stef Mientki <S.Mientki-nos...@mailbox.kun.nl>
wrote:

To the extent that you just want a group of people to
be able to organically organize a tree-like collection
of Python examples, you could use a MoinMoin that has
sensible page names and the Local Site Map featured
turn on.  Are you also suggesting the need for
something local, so that you can actually run the
programs?

___________________________________________________________________________ _________Luggage? GPS? Comic books?
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stef Mientki  
View profile  
 More options May 29 2007, 7:22 am
Newsgroups: comp.lang.python
From: Stef Mientki <S.Mientki-nos...@mailbox.kun.nl>
Date: Mon, 28 May 2007 23:22:53 +0200
Local: Tues, May 29 2007 7:22 am
Subject: Re: ten small Python programs

I don't know MoinMoin,
but the answer is Yes (although maybe not for your ten snippets).
First of all I think all programmers keep there own collection of code snippets,
which much more valuable then "all the code code snippets from everyone".
Secondly, Python is nowadays not only used by programmers,
but also by e.g. Scientific users (former MatLab users),
who are not interested in the code itself,
but just in the results of that particular code.
For these people a lot of example programs,
for which they can easily see the results,
make some small changes and see the result again,
would be a wonderful addition.

just my 2 cents,
cheers,
Stef Mientki


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steve Howell  
View profile  
 More options May 29 2007, 7:45 am
Newsgroups: comp.lang.python
From: Steve Howell <showel...@yahoo.com>
Date: Mon, 28 May 2007 14:45:26 -0700 (PDT)
Local: Tues, May 29 2007 7:45 am
Subject: Re: ten small Python programs

--- Stef Mientki <S.Mientki-nos...@mailbox.kun.nl> > >

> I don't know MoinMoin,
> but the answer is Yes (although maybe not for your
> ten snippets).
> First of all I think all programmers keep there own
> collection of code snippets,
> which much more valuable then "all the code code
> snippets from everyone".

Agreed.

> Secondly, Python is nowadays not only used by
> programmers,
> but also by e.g. Scientific users (former MatLab
> users),
> who are not interested in the code itself,
> but just in the results of that particular code.
> For these people a lot of example programs,
> for which they can easily see the results,
> make some small changes and see the result again,
> would be a wonderful addition.

In your own personal use, what are some
libraries/techniques/etc. that you think could benefit
from some kind of more organized presentation of
example programs (or better way of showing how the
examples work, etc.)?  Are you part of the Scientific
community?

How new are you to Python?  I do think
newbies/intermediates/advanceds all have different
needs.

___________________________________________________________________________ _________Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
http://smallbusiness.yahoo.com/webhosting


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
stef  
View profile  
 More options May 29 2007, 7:30 pm
Newsgroups: comp.lang.python
From: stef <s.mien...@id.umcn.nl>
Date: Tue, 29 May 2007 11:30:16 +0200
Local: Tues, May 29 2007 7:30 pm
Subject: Re: ten small Python programs

for example SciPy,
but I think it yield for all libs/techniques.
And I guess Windows users have a much greater need for such an
organization than *nix users.
>   Are you part of the Scientific
> community?

sort of, I indeed work at a university,
but not doing scientific work myself,
I work on a supporting department.

> How new are you to Python?

very new ;-)
(I've lot of experience in a other programming languages,
last years mostly Delphi, JAL, MatLab)

>   I do think
> newbies/intermediates/advanceds all have different
> needs.

agreed.

cheers,
Stef Mientki


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jacob Hallen  
View profile  
 More options Jun 8 2007, 6:32 pm
Newsgroups: comp.lang.python
From: ja...@cd.chalmers.se (Jacob Hallen)
Date: Fri, 8 Jun 2007 08:32:20 +0000 (UTC)
Local: Fri, Jun 8 2007 6:32 pm
Subject: Re: ten small Python programs
In article <mailman.8216.1180205410.32031.python-l...@python.org>,
Steve Howell  <showel...@yahoo.com> wrote:

>I've always thought that the best way to introduce new
>programmers to Python is to show them small code
>examples.  

Something like this:

http://www.lava.se/sam/

Jacob Hallén

--


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages < Older 
« Back to Discussions « Newer topic     Older topic »

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