Macros in Python?
Dominic
oblivious at web.de
Thu Apr 10 14:01:11 EDT 2003
> Alternatively, you can curry the above function:
>
> def with_root_privs(func):
> def call(func, *args, **kwargs):
> save_euid = os.geteuid()
> os.seteuid(0)
> try:
> func(*args, **kwargs)
> finally:
> os.seteuid(save_euid)
> return lambda *args, **kwargs: call(func, *args, **kwargs)
>
> You can then write something like the following:
>
> def activate_user(x):
> if x in user:
> active.append(x)
> ...
> activate_user = with_root_privs(activate_user)
> ...
> activate_user(x)
Thanks. This one is also very good. :-)
Interesting idea to use a closure to build
a function wrapper.
Ciao,
Dominic
More information about the Python-list
mailing list