The PEAK Developers' Center   SymbolType UserPreferences
HelpContents Search Diffs Info Edit Subscribe XML Print View
The following 138 words could not be found in the dictionary of 50 words (including 50 LocalSpellingWords) and are highlighted below:
But   Error   False   Installing   Last   List   Mailing   Note   Please   Simple   Specifically   Symbol   Symbols   The   Traceback   True   Type   You   able   access   allows   and   any   are   as   at   attributes   available   bar   be   being   built   but   by   call   can   cannot   changed   com   compare   correctly   create   created   defined   defining   details   direct   dumps   easy   eby   else   equal   exactly   find   for   forms   from   full   gives   giving   immutable   import   in   install   installing   is   it   its   know   last   least   level   list   listinfo   loads   mailing   mailman   means   module   most   must   name   not   object   objects   of   only   or   original   own   package   passed   peak   pickle   pickled   previously   provides   questions   reason   recent   regarding   repr   result   resulting   same   sarna   see   setup   so   str   strings   symbol   symbols   that   the   their   them   themselves   they   this   to   toolkit   two   type   unpickled   unpickling   used   using   util   want   way   when   where   will   with   within   you   your  

Clear message

Simple "Symbol" Type

Installing SymbolType (using "easy_install SymbolType" or " install") gives you access to the peak.util.symbols module, previously available only by installing the full PEAK toolkit. peak.util.symbols provides a Symbol type and two built-in symbols that are used by PEAK: NOT_FOUND and NOT_GIVEN. You can create your own symbol objects using the Symbol type, by giving it the symbol name and the name of the module where the symbol is being created:

>>> from peak.util.symbols import Symbol
>>> AN_EXAMPLE = Symbol('AN_EXAMPLE', __name__)

The resulting object's repr() and str() forms are the same as the name you passed in:


>>> str(AN_EXAMPLE)

But symbols compare equal only to themselves; they are not equal to strings:



A symbol's __name__ and __module__ attributes are the original name and module used to create the symbol:

>>> from peak.util.symbols import NOT_FOUND

>>> NOT_FOUND.__name__

>>> NOT_FOUND.__module__

The reason that symbols want to know their defining module is that this allows them to be pickled and unpickled correctly:

>>> import pickle
>>> pickle.loads(pickle.dumps(NOT_FOUND))

Specifically, it's so that the result of unpickling a symbol is exactly the same object as the original symbol:

>>> pickle.loads(pickle.dumps(NOT_FOUND)) is NOT_FOUND

Note that this means the symbol must be defined at module level within its module, with the same name that's passed in to it, or else pickle will not be able to find it when unpickling.

Last, but not least, symbol objects are immutable and cannot be changed in any way:

>>> = "bar"
Traceback (most recent call last):
TypeError: Symbols are immutable

Mailing List

Please direct questions regarding this package to the PEAK mailing list; see for details.

EditText of this page (last modified 2007-03-25 21:39:06)
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck