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