470,810 Members | 878 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Cookbook for beginners?

If you were going to name three or five essential recipes from the
Python Cookbook suitable for beginners, what would you pick?

Yes, this is for _Python for Dummies_, so idioms that aren't in the
Cookbook are also fine.
--
Aahz (aa**@pythoncraft.com) <*> http://www.pythoncraft.com/

"Look, it's your affair if you want to play with five people, but don't
go calling it doubles." --John Cleese anticipates Usenet
Mar 26 '06 #1
3 1455
Aahz:
If you were going to name three or five essential recipes from the
Python Cookbook suitable for beginners, what would you pick?
Yes, this is for _Python for Dummies_, so idioms that aren't in the
Cookbook are also fine.


Constants

Static methods / Class methods

Bunch

TaskQueue (Queue for easy and safe multithreading)

A decorator for type checking of function arguments, and/or for
require/ensure, and/or for similar features of other languages that people
find missing in Python.

Properties and in particular lazy properties. Why and how to avoid
getters/setters.

Dynamically import a module (name known at runtime, may or may not be
present).

Unittest/doctest.
Mar 26 '06 #2
Aahz a écrit :
If you were going to name three or five essential recipes from the
Python Cookbook suitable for beginners, what would you pick?

Yes, this is for _Python for Dummies_, so idioms that aren't in the
Cookbook are also fine.

1/ tuple- and dict-based dispatch, ie:
x = (result_if_false, result_if_true)[boolexpr]
y = {key1: result1, key2:result2, ...}[keyexpr]

2/ functions (and methods etc) as first-class objects (two main obvious
uses : callbacks and decorators)

+ (bonus) the combination of 1/ and 2/ !-)

3/ name-based lookups and affectations (getattr() / setattr()) and their
implementation ( __getattr__ / __setattr__)

Mar 26 '06 #3

Aahz wrote:
If you were going to name three or five essential recipes from the
Python Cookbook suitable for beginners, what would you pick?

Yes, this is for _Python for Dummies_, so idioms that aren't in the
Cookbook are also fine.


If it's for _beginners_ / _dummies_, I would expect things like

1.6
names = ['George', 'Saddam', 'Osama']
name_string = ', '.join(names)

4.10
dict.setdefault(k, v)

?.?
dict = dict(zip(list_a, list_b))

- listcomps

2.1 / 2.2
reading/writing from/to files

?.?
string-methods like .split(), .upper(), endswith(), startswith(),
isalpha() ...

Mar 26 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ringwraith | last post: by
reply views Thread by Alex Martelli | last post: by
7 posts views Thread by rdsteph | last post: by
reply views Thread by TechBookReport | last post: by
reply views Thread by Ralph Guzman | last post: by
reply views Thread by Frederick Noronha \(FN\) | last post: by
232 posts views Thread by robert maas, see http://tinyurl.com/uh3t | last post: by
3 posts views Thread by Steve Howell | last post: by
19 posts views Thread by yltkhuu | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.