Macros in Python?
Johann Hibschman
jhibschman at yahoo.com
Thu Apr 10 14:52:44 EDT 2003
Dominic <oblivious at web.de> writes:
> > 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)
> Thanks. This one is also very good. :-)
> Interesting idea to use a closure to build
> a function wrapper.
Hm. Why not just do:
def with_root_privs(func):
def call(*args, **kwargs):
save_euid = os.geteuid()
os.seteuid(0)
try:
func(*args, **kwargs)
finally:
os.seteuid(save_euid)
return call
I don't see what that extra layer of indirection is gaining you.
-Johann
More information about the Python-list
mailing list