Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cookbook for beginners?

0 views
Skip to first unread message

Aahz

unread,
Mar 26, 2006, 11:18:32 AM3/26/06
to
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

Rene Pijlman

unread,
Mar 26, 2006, 12:52:27 PM3/26/06
to
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.

Bruno Desthuilliers

unread,
Mar 26, 2006, 4:46:22 PM3/26/06
to
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__)

Rune Strand

unread,
Mar 26, 2006, 1:55:14 PM3/26/06
to

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() ...

0 new messages