Cookbook for beginners?

A

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.
 
R

Rene Pijlman

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.
 
R

Rune Strand

Aahz said:
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() ...
 
B

Bruno Desthuilliers

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__)
 

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

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top