For the record, I found a way that works for me quite well now:

udict = {}
cdict = {}
docdict = {}

def var2(name,doc='',units='',domain1='real',latexname='',value =
-1234):
    '''
    Creates a symbolic variable in the given domain (standard:'real')
and with the given
    latexname. Further, it adds the string doc to docdict, the units
to udict and the value
    to cdict. All entries are optional except for name.
    Usage example:
        sage: var2('T_a','Air
temperature',units.temperature.kelvin,'real','T_{a,K}',298)
    '''
    if len(latexname)>0:
        z = var(name,domain = domain1,latex_name = latexname)
    else:
        z = var(name,domain = domain1)
    if len(doc) > 0:
        docdict[var(name)] = doc
    if len(units)>0:
        udict[var(name)] = var(name)*units
    if value != -1234:
        cdict[var(name)] = value
    return z

This allows me to define a symbolic variable, store the docstring, the
units and a standard value in separate dictionaries, and also specify
the domain and a latex_name, all in one line. Now, to see the
description, instead of typing "T_a?", I have to type "docdict[T_a]",
which is only a minor inconvenience and consistent with typing
"udict[T_a]" or "cdict[T_a]" to find out the units or standard value.

Another helpful routine to simplify the specification of units was
mentioned in another post:

for s in units.temperature.trait_names():
    globals()[s] = getattr(units.temperature,s)

This allows to write e.g.:
"T_a = var2('T_a', 'Air temperature', kelvin)"

instead of

"T_a = var2('T_a', 'Air temperature', units.temperature.kelvin)"

Thanks to everyone for their help!

Cheers
Stan

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to