Calling a function of a package from the shell

Wojtek Walczak gminick at hacker.pl
Wed Nov 13 09:28:35 EST 2002


Dnia Mon, 28 Oct 2002 17:20:10 +0000 (UTC), Albert Hofkamp napisał(a):
> I am writing a remote execution Python package called exec_proxy for Unix
> systems, and as part of the functionality, I need to start a Python program
> at the remote machine.
[...]
> ssh machine /usr/bin/python2 -c \
> 	"import exec_proxy.remote ; exec_proxy.remote.run()"
Use __import__ instead of import, for example:

% python -c "print getattr(__import__('sys'), 'version')"
2.2.2 (#1, Oct 16 2002, 18:08:06)
[GCC 2.95.3 20010315 (release)]

or a shorter version:

% python -c "s=__import__('sys'); print s.version"
2.2.2 (#1, Oct 16 2002, 18:08:06)
[GCC 2.95.3 20010315 (release)]

-- 
[ Wojtek gminick Walczak ][ http://gminick.linuxsecurity.pl/ ]
[ gminick (at) hacker.pl ][ gminick (at) underground.org.pl  ]



More information about the Python-list mailing list