@header@
 
 
matplotlib.cbook
index
/matplotlib/cbook.py

A collection of utility functions and classes.  Many (but not all)
from the Python Cookbook -- hence the name cbook

 
Modules
       
StringIO
errno
os
re
sys
traceback

 
Classes
       
Bunch
Null
RingBuffer
Sorter
__builtin__.dict(__builtin__.object)
Xlator

 
class Bunch
    Often we want to just collect a bunch of stuff together, naming each
item of the bunch; a dictionary's OK for that, but a small do- nothing
class is even handier, and prettier to use.  Whenever you want to
group a few variables:
 
  >>> point = Bunch(datum=2, squared=4, coord=12)
  >>> point.datum
 
  By: Alex Martelli
  From: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52308
 
  Methods defined here:
__init__(self, **kwds)

 
class Null
    Null objects always and reliably "do nothing."
 
  Methods defined here:
__call__(self, *args, **kwargs)
__delattr__(self, name)
__getattr__(self, name)
__init__(self, *args, **kwargs)
__nonzero__(self)
__repr__(self)
__setattr__(self, name, value)
__str__(self)

 
class RingBuffer
    class that implements a not-yet-full buffer
 
  Methods defined here:
__get_item__(self, i)
__init__(self, size_max)
append(self, x)
append an element at the end of the buffer
get(self)
Return a list of elements from the oldest to the newest.

 
class Sorter
    Sort by attribute or item
 
Example usage:
sort = Sorter()
 
list = [(1, 2), (4, 8), (0, 3)]
dict = [{'a': 3, 'b': 4}, {'a': 5, 'b': 2}, {'a': 0, 'b': 0},
{'a': 9, 'b': 9}]
 
 
sort(list)       # default sort
sort(list, 1)    # sort by index 1
sort(dict, 'a')  # sort a list of dicts by key 'a'
 
  Methods defined here:
__call__ = byItem(self, data, itemindex=None, inplace=1)
byAttribute(self, data, attributename, inplace=1)
byItem(self, data, itemindex=None, inplace=1)
sort = byItem(self, data, itemindex=None, inplace=1)

 
class Xlator(__builtin__.dict)
    All-in-one multiple-string-substitution class
 
Example usage:
 
text = "Larry Wall is the creator of Perl"
adict = {
"Larry Wall" : "Guido van Rossum",
"creator" : "Benevolent Dictator for Life",
"Perl" : "Python",
}
 
print multiple_replace(adict, text)
 
xlat = Xlator(adict)
print xlat.xlat(text)
 
 
Method resolution order:
Xlator
__builtin__.dict
__builtin__.object

Methods defined here:
__call__(self, match)
Handler invoked for each regex match
xlat(self, text)
Translate text, returns the modified text.

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Xlator' objects>
list of weak references to the object (if defined)

Methods inherited from __builtin__.dict:
__cmp__(...)
x.__cmp__(y) <==> cmp(x,y)
__contains__(...)
x.__contains__(y) <==> y in x
__delitem__(...)
x.__delitem__(y) <==> del x[y]
__eq__(...)
x.__eq__(y) <==> x==y
__ge__(...)
x.__ge__(y) <==> x>=y
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__gt__(...)
x.__gt__(y) <==> x>y
__hash__(...)
x.__hash__() <==> hash(x)
__init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
__iter__(...)
x.__iter__() <==> iter(x)
__le__(...)
x.__le__(y) <==> x<=y
__len__(...)
x.__len__() <==> len(x)
__lt__(...)
x.__lt__(y) <==> x<y
__ne__(...)
x.__ne__(y) <==> x!=y
__repr__(...)
x.__repr__() <==> repr(x)
__setitem__(...)
x.__setitem__(i, y) <==> x[i]=y
clear(...)
D.clear() -> None.  Remove all items from D.
copy(...)
D.copy() -> a shallow copy of D
get(...)
D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.
has_key(...)
D.has_key(k) -> True if D has a key k, else False
items(...)
D.items() -> list of D's (key, value) pairs, as 2-tuples
iteritems(...)
D.iteritems() -> an iterator over the (key, value) items of D
iterkeys(...)
D.iterkeys() -> an iterator over the keys of D
itervalues(...)
D.itervalues() -> an iterator over the values of D
keys(...)
D.keys() -> list of D's keys
pop(...)
D.pop(k[,d]) -> v, remove specified key and return the corresponding value
If key is not found, d is returned if given, otherwise KeyError is raised
popitem(...)
D.popitem() -> (k, v), remove and return some (key, value) pair as a
2-tuple; but raise KeyError if D is empty
setdefault(...)
D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D
update(...)
D.update(E) -> None.  Update D from E: for k in E.keys(): D[k] = E[k]
values(...)
D.values() -> list of D's values

Data and other attributes inherited from __builtin__.dict:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T
fromkeys = <built-in method fromkeys of type object>
dict.fromkeys(S[,v]) -> New dict with keys from S and values equal to v.
v defaults to None.

 
Functions
       
enumerate(seq)
# until 2.3
exception_to_str(s=None)
flatten(seq, scalarp=<function is_scalar>)
this generator flattens nested containers such as
 
>>> l=( ('John', 'Hunter'), (1,23), [[[[42,(5,23)]]]])
 
so that
 
>>> for i in flatten(l): print i,
John Hunter 1 23 42 5 23
 
By: Composite of Holger Krekel and Luther Blissett
From: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/121294
and Recipe 1.12 in cookbook
get_recursive_filelist(args)
Recurs all the files and dirs in args ignoring symbolic links and
return the files as a list of strings
get_split_ind(seq, N)
seq is a list of words.  Return the index into seq such that
len(' '.join(seq[:ind])<=N
is_scalar(obj)
is_string_like(obj)
iterable(obj)
listFiles(root, patterns='*', recurse=1, return_folders=0)
Recursively list files
from Parmar and Martelli in the Python Cookbook
mkdirs(newdir, mode=511)
pieces(seq, num=2)
Break up the seq into num tuples
soundex(name, len=4)
soundex module conforming to Odell-Russell algorithm
wrap(prefix, text, cols)

 
Data
        False = False
True = True
generators = _Feature((2, 2, 0, 'alpha', 1), (2, 3, 0, 'final', 0), 4096)
major = 2
minor1 = 3
minor2 = 2
s = 'final'
tmp = 0
@footer@