By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,313 Members | 1,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,313 IT Pros & Developers. It's quick & easy.

How to call a script from another?

P: n/a
From a not even newbie:

Without knowing much about Python (yet) I'm trying to install the CMS
Zope via FTP (with the well documented changes to make it work on an
Apache server).
By birth Zope is started from a shell script. And not having the
permissions to execute such ones I'll try writing a .py script (with the
shebang that I allready knows will do the job) to call another .py
script like the original shell script does.

So my question is:
How do I call a .py script from another .py script?
(Writing the rest - I hope - is piece of cake ;-) ).

(And yes, I know that there are a lot of other problems but for starters
I just would like to try to call a .py script from another .py script.)
Thanks

Chris
Oct 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I think this is the simplest way to do that:

import sys
sys.path.append('/path/to/directory/containg/script')

import zopescript
zopescript.main()

The code above assumes:
o that the path you use to append contains an __init__.py in it...
o zopescript is the module you want to `run'
o main is the method in zopescript that cranks up zope.

I'm not sure of how to do it the hard way...

jw

On 10/13/05, Christian <ch*******@spam.no> wrote:
From a not even newbie:

Without knowing much about Python (yet) I'm trying to install the CMS
Zope via FTP (with the well documented changes to make it work on an
Apache server).
By birth Zope is started from a shell script. And not having the
permissions to execute such ones I'll try writing a .py script (with the
shebang that I allready knows will do the job) to call another .py
script like the original shell script does.

So my question is:
How do I call a .py script from another .py script?
(Writing the rest - I hope - is piece of cake ;-) ).

(And yes, I know that there are a lot of other problems but for starters
I just would like to try to call a .py script from another .py script.)
Thanks

Chris
--
http://mail.python.org/mailman/listinfo/python-list

Oct 13 '05 #2

P: n/a
Jaime Wyant wrote:
I think this is the simplest way to do that:

import sys
sys.path.append('/path/to/directory/containing/script')

import zopescript
zopescript.main()

The code above assumes:
o that the path you use to append contains an __init__.py in it...

I don't think this is necessary. The __init__.py is necessary
if you do something like:
import sys
sys.path.append('/path/to/directory/containing')
from script import zopescript
zopescript.main()
# or import zopescript.script; script.zopescript.main()
That is, if the directory ".../containing" needs to be interpreted as
a package.

If the script you want to call is in the same directory as the script
calling it (or any directory on the path), you can simply use:
import zopescript
zopescript.main()

--Scott David Daniels
sc***********@acm.org
Oct 13 '05 #3

P: n/a
Thanks guy's, you have opened my eyes and made my next step a whole lot
easier.
Chris
Oct 13 '05 #4

P: n/a
On Thu, 13 Oct 2005 16:29:37 +0200, Christian <ch*******@spam.no>
declaimed the following in comp.lang.python:
By birth Zope is started from a shell script. And not having the
permissions to execute such ones I'll try writing a .py script (with the
shebang that I allready knows will do the job) to call another .py
script like the original shell script does.
Pardon? If you can't execute "shell scripts", how do you intend to
execute the python script to execute the other python script?
So my question is:
How do I call a .py script from another .py script?
(Writing the rest - I hope - is piece of cake ;-) ).
Well... an overly simplified explanation... You create a command
shell and pass the name of the script to it (back to problem #1)

import os
os.system("python myOtherPython.py")

{If you have a new enough Python release, there is a subprocess module
that has a bit more capability}
(And yes, I know that there are a lot of other problems but for starters
I just would like to try to call a .py script from another .py script.)
OTOH, if the script is designed as an importable module, you could

import myOtherPython
myOtherPython.mOP_main_entry_point()

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Oct 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.