| |
- Relations
class Relations |
|
Class to handle conversion of string based name to its respective
value. The name and its value is stored in a file which is passed on
as a parameter to the constructor. Null cannot occupy the position of
key. White space characters are stripped from either ends of key
and value. All lines starting with `#' is ignored.
A sample relations file (ignore '|'):
|# <- file begins.
|database: mySQL
|dbuser: ashish
|dbpass: ^1al00@2$
|linecount: 25
|linewidth: 80
|# <- file ends.
A sample script using class Relations and associated methods (ignore '|'):
|# <- script begins.
|from prangya.relations import *
|try :
| rel = Relations('/etc/passwd')
|except IOError, mesg:
| print mesg.error
|else :
| print 'Details for "root" are:'
| print rel._('root')
| print 'List of system users are:'
| print rel.keys()
| print 'List of details for each user are:'
| print rel.values()
|# <- script ends. |
|
Methods defined here:
- _(self, key)
- The member function to determine the value of a particular key.
If the key does not exist, an exception(KeyError) is raised.
- __init__(self, filename)
- Constructor which takes a file as parameter. The contents of the file
are key value pairs separated by colon(:).
- keys(self)
- The member function to return all keys currently held by the instance
of this class. The ordering of the keys are random.
- values(self)
- The member function to return values for all the keys currently held
by the instance of this class. The ordering of the values are random.
Data and non-method functions defined here:
- __doc__ = '\n Class to handle conversion of string base...print rel.values()\n |# <- script ends.\n '
- __module__ = 'prangya.relations'
| |