By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,020 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,020 IT Pros & Developers. It's quick & easy.

Python Code Snippets

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
You're gonna love this :)

http://aspn.activestate.com/ASPN/Cookbook/Python
"Aurélien Géron" <ag****@HOHOHOHOvideotron.ca> wrote in message
news:be***********@biggoron.nerim.net...
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

Jul 18 '05 #2

P: n/a
Guyon Morée wrote:
You're gonna love this :)

http://aspn.activestate.com/ASPN/Cookbook/Python
"Aurélien Géron" <ag****@HOHOHOHOvideotron.ca> wrote in message
news:be***********@biggoron.nerim.net...
Hi,

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

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 Scalet wrote: 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"? ;)

Jul 18 '05 #3

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

Aurélien

"Guyon Morée" <gu***@looze.net> a écrit dans le message de
news:3f**********************@news.nl.uu.net...
You're gonna love this :)

http://aspn.activestate.com/ASPN/Cookbook/Python
"Aurélien Géron" <ag****@HOHOHOHOvideotron.ca> wrote in message
news:be***********@biggoron.nerim.net...
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


Jul 18 '05 #4

P: n/a

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

Jul 18 '05 #5

P: n/a
Behrang Dadsetan wrote:
Guyon Morée wrote:
You're gonna love this :)

http://aspn.activestate.com/ASPN/Cookbook/Python
"Aurélien Géron" <ag****@HOHOHOHOvideotron.ca> wrote in message
news:be***********@biggoron.nerim.net...
Hi,

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


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 Scalet wrote:
> 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."

--
rzed

Jul 18 '05 #6

P: n/a
On Thu, 3 Jul 2003, Aurélien Géron wrote:
Does anyone know where I can find a lot of Python code snippets?


Try:

http://www.faqts.com/knowledge_base/index.phtml/fid/538

Cheers,

/Mickel

--
Mickel Grönroos, application specialist, linguistics, Research support, CSC
PL 405 (Tekniikantie 15 a D), 02101 Espoo, Finland, phone +358-9-4572237
CSC is the Finnish IT center for science, www.csc.fi
Jul 18 '05 #7

P: n/a
"Aurélien Géron" <ag****@HOHOHOHOvideotron.ca> wrote in message news:<be***********@biggoron.nerim.net>...
Hi,

Does anyone know where I can find a lot of Python code snippets? <snip> 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
Jul 18 '05 #8

P: n/a
> 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.

Jul 18 '05 #9

P: n/a
"Aurélien Géron" <ag****@HOHOHOHOvideotron.ca> writes:
Does anyone know where I can find a lot of Python code snippets?

[...]

http://www.uselesspython.com/

They're working on useless 2, with categories.
John
Jul 18 '05 #10

P: n/a
In article <be***********@biggoron.nerim.net>,
Aurélien Géron <ag****@HOHOHOHOvideotron.ca> wrote:
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.

Jul 18 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.