How to search code snippets

Question:

For example I want to know how to use Python pickle serialization & deserialization. Since I’ve never use it, reading Python official doc would be a great reference, but I prefer some snippets/example codes either has description or not. Like sites for python beginners, someone’s blog, or from google codes.

How would you search? Like go to specific sites, or use what keyword. Actually this is a general question not only for Python, but for learning all languages. Thanks.

Asked By: Stan

||

Answers:

Google Code Search.

From the FAQ:

We’re crawling as much publicly
accessible source code as we can find,
including archives (.tar.gz, .tar.bz2,
.tar, and .zip), CVS repositories and
Subversion repositories.

Sample search: http://www.google.com/codesearch?q=lang%3Apython+%22cpickle%22

The operators are handy:

  • The lang: operator, which restricts by programming language (e.g., lang:”c++”, -lang:java, or lang:^(c|c#|c++)$)
  • The license: operator, which restricts by software license (e.g., license:apache, -license:gpl, or license:bsd|mit)
  • The package: operator, which restricts by package URL (e.g., package:”www.kernel.org” or package:.tgz$)
  • The file: operator, which restricts by filename (e.g., file:include/linux/$ or -file:.cc$)
Answered By: mechanical_meat

In general, Google Code Search is a pretty good place to look for code snippets. To look for Python pickle examples, I’d do a search like

lang:python pickle examples
Answered By: rettops

You can also look at Activestate Python Recipe’s:
http://code.activestate.com/recipes/langs/python/

Here’s their recipes for Python Pickling:
http://code.activestate.com/search/#q=pickle python

O’Reilly’s Python Cookbook is also good. You can read it online with a Safari membership.

Answered By: Anton I. Sipos

There is also Nullege. A search engine especially for Python code.

Answered By: Paidhi

The Github search is pretty good. It’s usually used to search for repository but its search code works well:

enter image description here

enter image description here

Answered By: ThePhi
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.