Python Code Snippets

  • Thread starter Aurélien Géron
  • Start date
A

Aurélien Géron

Hi,

Does anyone know where I can find a lot of Python code snippets?

I searched the Python wiki and Internet but could not find more than five or
ten code snippets at a time.

I'm looking for a kind of organized list (GUI snippets, database access
snippets, I/O snippets, etc.). I find that there's no better way to learn a
language than to be able to cut&paste actual working bits of code.

Thanks,
Aurélien
 
B

Behrang Dadsetan

Guyon said:

Or you might want to just look around here. In this
newsgroup/mailing-list one gets to see really lots of nice code.

One that I would nominate as the best test for measuring a hard-core
python programmer would be to explain the following code without the
context :)

Karl said:
> there are very likely easier ways, but at least
>
> s = 'C6 H12 O6'
> print [' '.join(xx) for xx in apply(
> zip,[(x[0],x[1:]) for x in s.split()])]
>
> gives some results,
>
> Karl

Once I understood the above, I beleive I will write python in my Resume...

What was this about "One simple obvious way doing it"? ;)
 
A

Aurélien Géron

Hey thanks !
I wish it had a better ordering than just a list, but it's full of good
stuff.

Aurélien
 
S

Skip Montanaro

Aurélien> I wish it had a better ordering than just a list, but it's
Aurélien> full of good stuff.

You can always buy the book. It has both an index and a table of contents.

Skip
 
R

rzed

Behrang said:
Guyon said:

Or you might want to just look around here. In this
newsgroup/mailing-list one gets to see really lots of nice code.

One that I would nominate as the best test for measuring a hard-core
python programmer would be to explain the following code without the
context :)

Karl said:
there are very likely easier ways, but at least

s = 'C6 H12 O6'
print [' '.join(xx) for xx in apply(
zip,[(x[0],x[1:]) for x in s.split()])]

gives some results,

Karl

Once I understood the above, I beleive I will write python in my
Resume...

What was this about "One simple obvious way doing it"? ;)

Obviously, this is just what people mean by "syntactic sugar."
 
P

Paul Simmonds

Aurélien Géron said:
Hi,

Does anyone know where I can find a lot of Python code snippets?
I'm looking for a kind of organized list (GUI snippets, database access
snippets, I/O snippets, etc.). I find that there's no better way to learn a
language than to be able to cut&paste actual working bits of code.
<snip>
Hi,
As well as the excellent resources others have mentioned, I'd
definately recommend investigating the Python source distribution, if
you haven't already. The joy of working with an Open Source language
is that there's no problem if you want to look at some decent code:

The Lib and Demo directories provide examples from the simple to the
not-so-simple in a variety of application domains.

The Objects and Include directories provide good examples of using the
Python-C API. Seeing how the objects are created under the hood has
increased my understanding of how Python works, and the quality of my
C extensions.

I'd also say the online Cookbook has a reasonable search facility, and
lists of recipies from different areas, so it is relatively easy to
find a particular code snippet.

HTH,
Paul
 
B

Bernard Delmée

Aurélien> I wish it had a better ordering than just a list, but
it's Aurélien> full of good stuff.

You can always buy the book. It has both an index and a table of
contents.

IMO not ideally suited to learning the language, but an
invaluable compendium of idioms and advanced topics

Sample chapter available at
http://www.oreilly.com/catalog/pythoncook/

Other multi-language code samples repositories I know of:
http://sourceforge.net/snippet/
and
http://pleac.sourceforge.net/

CHeers,

Bernard.
 
C

Cameron Laird

Hi,

Does anyone know where I can find a lot of Python code snippets?

I searched the Python wiki and Internet but could not find more than five or
ten code snippets at a time.

I'm looking for a kind of organized list (GUI snippets, database access
snippets, I/O snippets, etc.). I find that there's no better way to learn a
language than to be able to cut&paste actual working bits of code.
.
.
.
Along with everything the others have offered, "Python-URL!"
<URL: http://www.ddj.com/topics/pythonurl/ > offers a con-
centrated dose of the week's highlights. You might find
that useful in the regard you describe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top