External Methods newbie question
Hello, I see I can only execute python functions in external methods. Is there any way to execute the whole file, not just a certain function? In linux I created a python script, and it doesn't have functions. I just want to execute the whole file. I tried using "self" or "init" for function names in Zope and it doesn't want to do it, telling me "The specified object, init, was not found in module, test." Is there a way to execute a file? (another question: is there a way to execute bash commands in linux? or is external methods only good for python?) Thanks in advance guys!! --------------------------------- Yahoo! Mail Use Photomail to share photos without annoying attachments.
--On 28. Februar 2006 17:14:50 -0800 Alric Aneron <aluminum3458@yahoo.com> wrote:
Hello, I see I can only execute python functions in external methods. Is there any way to execute the whole file, not just a certain function? In linux I created a python script, and it doesn't have functions. I just want to execute the whole file. I tried using "self" or "init" for function names in Zope and it doesn't want to do it, telling me "The specified object, init, was not found in module, test."
Is there a way to execute a file?
This is basically a Pyhthon question. Look at os.system(), the subprocess module, popenX calls....the Python Library Reference is your friend. -aj
I don't understand your question regarding 'execute the whole file'? Why can't you just put all of the python commands you want into an external method, then use a single 'main-line function' to call the 'sub-functions' as needed? python has a command called 'commands' which can be used for executing bash commands. hth Jonathan ----- Original Message ----- From: Alric Aneron To: zope@zope.org Sent: Tuesday, February 28, 2006 8:14 PM Subject: [Zope] External Methods newbie question Hello, I see I can only execute python functions in external methods. Is there any way to execute the whole file, not just a certain function? In linux I created a python script, and it doesn't have functions. I just want to execute the whole file. I tried using "self" or "init" for function names in Zope and it doesn't want to do it, telling me "The specified object, init, was not found in module, test." Is there a way to execute a file? (another question: is there a way to execute bash commands in linux? or is external methods only good for python?) Thanks in advance guys!! ------------------------------------------------------------------------------ Yahoo! Mail Use Photomail to share photos without annoying attachments. ------------------------------------------------------------------------------ _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
thanks guys, I'll try Andreas Jung <lists@andreas-jung.com> wrote: --On 28. Februar 2006 20:26:13 -0500 Jonathan wrote:
python has a command called 'commands' which can be used for executing bash commands.
talk about modules, not commands. -aj --------------------------------- Yahoo! Mail Bring photos to life! New PhotoMail makes sharing a breeze.
To executed a "whole file" you need to wrap it as a function -- def foo( self ): <the script> and call foo as an external method. The self argument gives the context. Python provides several modules which give access to execute bash commands, linux commands, etc. Look at the modules subprocess and commands. On Tue, 28 Feb 2006, Alric Aneron wrote:
Hello, I see I can only execute python functions in external methods. Is there any way to execute the whole file, not just a certain function? In linux I created a python script, and it doesn't have functions. I just want to execute the whole file. I tried using "self" or "init" for function names in Zope and it doesn't want to do it, telling me "The specified object, init, was not found in module, test."
Is there a way to execute a file?
(another question: is there a way to execute bash commands in linux? or is external methods only good for python?)
Alric Aneron schrieb:
Hello, I see I can only execute python functions in external methods. Is there any way to execute the whole file, not just a certain function? In linux I created a python script, and it doesn't have functions. I just want to execute the whole file. I tried using "self" or "init" for function names in Zope and it doesn't want to do it, telling me "The specified object, /init/, was not found in module, /test/."
Is there a way to execute a file?
Yes, you can use os.popen* for example - but what is the point? You would waste memory and CPU cycles in firing another complete interpreter environment. Instead move the commands in the "file" into a function, use the common pattern: def main(): foo.. bar... if __name__=='__main__': main() As you see in many modules. This was you just import the "file" as module in your external method and call yourmodule.main()
(another question: is there a way to execute bash commands in linux? or is external methods only good for python?)
What are bash commands? Builtin commands like if, fi, while, case etc? Or do you mean just external executables (binaries, scripts)? And if so, what are they fore? Python is very capable and you can do most with it as easy/easier then with extra commands. If not, see above for os.popen and friends. Regards Tino
participants (5)
-
Alric Aneron -
Andreas Jung -
Dennis Allison -
Jonathan -
Tino Wildenhain