changing local namespace of a function

M.E.Farmer mefjr75 at hotmail.com
Sat Feb 5 02:25:45 EST 2005


>It is ugly, unreadable and error prone. If I have to use this code, I
>would write
>   _z = func(_x + _y + _whatever['as'] + _a[0])
>and use a perl script to generate the real code. (See, I am not lazy
:-)
Ok laziness is an acceptable answer ;)
This is starting to make sense , you've been reading Perl's 'dense'
code and are not used to Python's explicitness.
 *Explicit is better than implicit!*
It is a Zen of Python. Also I notice you say you will probably use the
'evil hack'.
Uhmmm, it is labeled evil hack for a reason! So go ahead and make life
hard and save a few keystrokes. There is a reason for the verbosity of
Python.
I really don't completly follow what you are trying to construct here
but it seems like you need to create an adapter class of some sort and
use that ( much like Jeff Shannon or Michael Spencer mentioned )
As a general rule class abstraction is your friend in Python.
It looks like ultimatly you are just using dictionary's and want to do
inplace operations on some of the data and store the results in other
parts of the dictionary... If that is the case then why not creat a few
helper functions that do exactly one thing each and use them as your
interface.

Py> def fun_helper(d):
...   d['z'] = func(d['x']+d['y']+d['whatever']['as']+d[a][0])
...   return d

and use them as needed.

M.E.Farmer




More information about the Python-list mailing list