The persistence module¶
Class¶
An
Archive
object can be used to marshal a set of uncertain numbers for storage, or restore a set of uncertain numbers from storage.Python pickle is used for the storage mechanism.
Functions¶
Module contents¶
-
class
Archive
¶ An
Archive
object can be used to marshal a set of uncertain numbers for storage, or restore a set of uncertain numbers from storage.-
add
(**kwargs)¶ Add entries
name = uncertain-number
to the archiveExample:
>>> a = Archive() >>> x = ureal(1,1) >>> y = ureal(2,1) >>> a.add(x=x,fred=y)
-
extract
(*args)¶ Extract one or more uncertain numbers
Parameters: args – names of archived uncertain numbers If just one name is given, a single uncertain number is returned, otherwise a sequence of uncertain numbers is returned.
# Example:
# >>> x, fred = a.extract('x','fred') # >>> harry = a.extract('harry')
-
items
()¶ Return a list of name -to- uncertain-number pairs
-
iteritems
()¶ Return an iterator of name -to- uncertain-number pairs
-
iterkeys
()¶ Return an iterator for names
-
itervalues
()¶ Return an iterator for uncertain numbers
-
keys
()¶ Return a list of names
-
values
()¶ Return a list of uncertain numbers
-
-
load
(file)¶ Load an archive from a file
Parameters: file – a file object opened in binary read mode (with ‘rb’) Several archives can be extracted from one file by repeatedly calling this function.
-
dump
(file, ar)¶ Save an archive in a file
Parameters: - file – a file object opened in binary write mode (with ‘wb’)
- ar – an
Archive
object
Several archives can be saved in a file by repeated use of this function.
-
dumps
(ar, protocol=4)¶ Return a string representation of the archive
Parameters: - ar – an
Archive
object - protocol – encoding type
Possible values for
protocol
are described in the Python documentation for the ‘pickle’ module.protocol=0
creates an ASCII string, but note that many (special) linefeed characters are embedded.- ar – an