Re: How to refer to the current module?

2008-01-07 Thread Stargaming
On Mon, 07 Jan 2008 05:21:42 -0800, Mike wrote: > I want to do something like the following (let's pretend that this is in > file 'driver.py'): > > #!/bin/env python > > import sys > > def foo(): > print 'foo' > > def bar(arg): > print 'bar with %r' % arg > > def main(): > getattr

Re: How to refer to the current module?

2008-01-07 Thread Christian Heimes
Mike wrote: > Is there any way around this? Can I somehow scope the 'current > module' and give getattr(...) an object that will (at run time) have > the appropriate bindings? globals() for the current name space import sys sys.modules[__name__] gets you the module object Christian -- http://

Re: How to refer to the current module?

2008-01-07 Thread Jean-Paul Calderone
On Mon, 7 Jan 2008 05:21:42 -0800 (PST), Mike <[EMAIL PROTECTED]> wrote: >I want to do something like the following (let's pretend that this is >in file 'driver.py'): > >#!/bin/env python > >import sys > >def foo(): >print 'foo' > >def bar(arg): >print 'bar with %r' % arg > >def main(): >

Re: How to refer to the current module?

2008-01-07 Thread Mike
Sweet! Thanks! Mike On Jan 7, 8:30 am, "Guilherme Polo" <[EMAIL PROTECTED]> wrote: > > globals() =) > -- http://mail.python.org/mailman/listinfo/python-list

Re: How to refer to the current module?

2008-01-07 Thread Guilherme Polo
2008/1/7, Mike <[EMAIL PROTECTED]>: > I want to do something like the following (let's pretend that this is > in file 'driver.py'): > > #!/bin/env python > > import sys > > def foo(): > print 'foo' > > def bar(arg): > print 'bar with %r' % arg > > def main(): > getattr(driver, sys.argv[

How to refer to the current module?

2008-01-07 Thread Mike
I want to do something like the following (let's pretend that this is in file 'driver.py'): #!/bin/env python import sys def foo(): print 'foo' def bar(arg): print 'bar with %r' % arg def main(): getattr(driver, sys.argv[1])(*sys.argv[2:]) if __name__=='__main__': main() Ess