| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DybPython::Tools Namespace Reference


Functions

def realpath
def mapify
def unitify

Function Documentation

def DybPython::Tools::realpath (   pathname  ) 

Return the absolute path with environment variables and
symbolic links expanded.

Definition at line 7 of file Tools.py.

00007                         :
00008     '''Return the absolute path with environment variables and
00009     symbolic links expanded.'''
00010     from os import path
00011     return path.normpath( path.realpath( path.expandvars(pathname) ) )
00012 
def mapify(string):

def DybPython::Tools::mapify (   string  ) 

Parse string, return dictionary.  The string can be either in
the form of a Python dictionary, in which case it is simply
eval'ed or it can be of the simpler form of key/value pairs
separated by a colon (":") and with pairs separated with spaces.
This simpler form assumes all keys and values are themselves to be
interpreted as strings unless they begin with an "[" in which case
they will be eval'ed.

Definition at line 13 of file Tools.py.

00013                   :
00014     '''Parse string, return dictionary.  The string can be either in
00015     the form of a Python dictionary, in which case it is simply
00016     eval'ed or it can be of the simpler form of key/value pairs
00017     separated by a colon (":") and with pairs separated with spaces.
00018     This simpler form assumes all keys and values are themselves to be
00019     interpreted as strings unless they begin with an "[" in which case
00020     they will be eval'ed.'''
00021     if "{" in string and "}" in string: 
00022         return eval(string)
00023 
00024     ret = {}
00025     kvs = string.split()
00026     for kv in kvs:
00027         k,v = kv.split(":")
00028         if v[0] == '[': 
00029             v = eval(v)         # turn into list object
00030         ret[k] = v
00031         continue
00032     return ret
00033 
def unitify(string, default_unit=None):

def DybPython::Tools::unitify (   string,
  default_unit = None 
)

Evaluate the given string in a context with units defined.  If
default_unit is given it will be implicitly multiplied 

Examples:

1 == unitify("1")
1.1 == unitify("1.1")
1000000000.0 == unitify("second")
1000000000.0 == unitify("1*second")
1000000000.0 == unitify("1","second")
1000000000.0 == unitify("1",units.second)

Definition at line 34 of file Tools.py.

00034                                       :
00035     '''Evaluate the given string in a context with units defined.  If
00036     default_unit is given it will be implicitly multiplied 
00037     
00038     Examples:
00039 
00040     1 == unitify("1")
00041     1.1 == unitify("1.1")
00042     1000000000.0 == unitify("second")
00043     1000000000.0 == unitify("1*second")
00044     1000000000.0 == unitify("1","second")
00045     1000000000.0 == unitify("1",units.second)
00046 
00047     '''
00048 
00049     import GaudiKernel.SystemOfUnits as units
00050 
00051     try:                        # check if it is a pure number
00052         num = eval(string,{},{})
00053     except NameError:           # must not be
00054         return eval(string,units.__dict__)
00055     if default_unit:
00056         return eval ("%s*%s"%(num,default_unit),units.__dict__)
00057     return num
00058 
00059 
00060     
    

| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:13:03 2011 for DybPython by doxygen 1.4.7