This link has been bookmarked by 98 people . It was first bookmarked on 27 Jun 2007, by x y.
-
10 May 12
-
18 Feb 12
-
11 Feb 12
-
17 Oct 11
-
03 Mar 11
-
21 Dec 10
-
06 Dec 10
-
15 Sep 10
-
28 Jun 10
-
28 Jan 10
zarakin nikarazAuthor: C Titus Brown
Date: June 18, 2007
Welcome! You have stumbled upon the class handouts for a course I taught at Lawrence Livermore National Lab, June 12-June 14, 2007.
These notes are intended to accompany my lecture, which was a demonstration of a -
17 Jan 10
-
05 Oct 09
-
30 Jul 09
-
26 Jun 09
-
25 Jun 09
-
19 Apr 09
-
18 Apr 09
-
16 Apr 09
Luciano PachecoThere are a bunch of neat things you can do with classes, but one of the neatest is building new types that can be used with standard Python list/dictionary idioms.
development python tutorial programming reference testing course delicious
-
13 Apr 09
-
05 Mar 09
Andrew PerryC Titus Brown's course notes on "intermediate" Python programming topics
-
20 Nov 08
-
29 Oct 08
-
22 Oct 08
-
22 Jul 08
-
-
but I think the clearest option is to use enumerate:
-
The key point here is that d.get(k, default) is equivalent to d[k] if d[k] already exists; otherwise, it returns default.
-
[ expression for var in list if conditional ]
-
def __getitem__(self, index):
-
def __len__(self):
-
an iterator isn't really a type, but a protocol.
-
Here, __iter__ just returns self, an object that has the function next(), which (when called) either returns a value or raises a StopIteration exception.
-
Essentially, they're functions that let you suspend execution and return a result:
-
It is also much easier to write routines like enumerate as a generator than as an iterator:
-
A Python package is a directory full of Python modules containing a special file, __init__.py, that tells Python that the directory is a package.
-
you can restrict what objects are exported from a module or package by listing the names in the __all__ variable
-
The reload function will reload the module and force re-execution at the top level:
-
setup.py and distutils: the old fashioned way of installing Python packages
-
setup.py, eggs, and easy_install: the new fangled way of installing Python packages
-
Unit tests with unittest
-
First, start by writing a test for each bug as they are discovered.
-
They're exactly what you think: unordered collections of values.
-
all and any are two new functions in Python that work with iterables (e.g. lists, generators, etc.). any returns True if any element of the iterable is True (and False otherwise); all returns True if all elements of the iterable are True (and False otherwise).
-
Briefly, function decorators are functions that take functions as arguments, and return other functions.
-
Second, adding attributes to functions. (This is why I use them in my testing code sometimes.)
-
Here, *args assigns all of the positional arguments to a tuple 'args', and '**kwargs' assigns all of the keyword arguments to a dictionary 'kwargs':
-
Speeding Up Python
-
There's an excellent guide to Pyrex available online here: http://ldots.org/pyrex-guide/.
-
Based on my little survey above, I would suggest using SWIG to write wrappers for relatively small libraries, while SIP probably provides a more manageable infrastructure for wrapping large libraries (which I know I did not demonstrate!)
-
Now, the way this is implemented behind the scenes is that there's a dictionary hiding in 'n' (called 'n.__dict__') that holds all of the attributes. However, dictionaries consume a fair bit of memory above and beyond their contents, so it might be good to get rid of the dictionary in some circumstances and specify precisely what attributes a class has.
-
Python 2.2 introduced "managed attributes". With managed attributes, you can define functions that handle the get, set, and del operations for an attribute:
-
This can actually give you control over things like the types of objects that are assigned to particular classes: no mean thing.
-
The biggest point is that Python 3000 will break backwards compatibility, abruptly.
-
-
26 Apr 08
-
04 Apr 08
-
02 Apr 08
-
17 Mar 08
-
04 Mar 08
-
05 Feb 08
-
08 Jan 08
-
13 Nov 07
-
03 Nov 07
-
20 Oct 07
-
>>> def simple_cache(fn): ... cache = {} ... ... def new_fn(n): ... if n in cache: ... print 'FOUND IN CACHE; RETURNING' ... return cache[n] ... ... # otherwise, call function & record value ... val = fn(n) ... cache[n] = val ... return val ... ... return new_fn
-
try: import psyco psyco.full() except ImportError: pass
-
-
29 Sep 07
-
25 Sep 07
-
27 Jul 07
-
06 Jul 07
-
05 Jul 07
-
03 Jul 07
Heinz Wittenbrink'These notes are intended to accompany my lecture, which was a demonstration of a variety of "intermediate" Python features and packages... they have been updated from my actual handouts to be more complete...'
-
02 Jul 07
-
01 Jul 07
-
30 Jun 07
-
Chris HardingWelcome! You have stumbled upon the class handouts for a course I taught at Lawrence Livermore National Lab, June 12-June 14, 2007.
These notes are intended to accompany my lecture, which was a demonstration of a variety of "intermediate" Python featur -
29 Jun 07
-
28 Jun 07
-
27 Jun 07
-
gialloporporaThese notes are intended to accompany my lecture, which was a demonstration of a variety of "intermediate" Python features and packages. Because the demonstration was interactive, these notes are not complete notes of what went on in the course. (Sorry ab
-
25 Jun 07
-
24 Jun 07
Chris LasherTitus Brown's materials from his three-day LLNL workshop.
for:gamezace for:gvwilson optimization programming python python3000 softwarecarpentry unittesting
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.