473,479 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to call a script from another?

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
4 4105
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
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
Thanks guy's, you have opened my eyes and made my next step a whole lot
easier.
Chris
Oct 13 '05 #4
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5259
by: Greg Chapman | last post by:
I am at my wit's end trying to get information out of Streamline.net's support dept about my problem. They reply quickly enough, but seem to try and give out the least possible amount of info each...
3
48750
by: Tubby Tudor | last post by:
What is the best way to call one python script from within another python script? For example: one.py finishes succesfully and calls two.py which finishes OK and then calls three.py Thanks...
3
4012
by: JoeK | last post by:
Hey all, I am automating a web page from Visual Foxpro. I can control all the textboxes, radio buttons, and command buttons using syntax such as: ...
7
3235
by: priya.tweety | last post by:
How to call a js file from another js file?
10
24031
by: bienwell | last post by:
Hi, I have a question about file included in ASP.NET. I have a file that includes all the Sub functions (e.g FileFunct.vb). One of the functions in this file is : Sub TestFunct(ByVal...
3
3576
by: KaNos | last post by:
Hi, "robot script pages" are html+javascript pages, can be played in aspx player. So in this tech, robot call aspx player's function (an interface is sheared) and wait a result synchronously with...
2
2075
by: harishdixit1 | last post by:
Hello friends i developed a tollbar for Firefox browser. Now This toolbar contains a menu item. A web page will be opened by the user of the Toolbar. This Web page source code has included many .JS...
1
1214
by: Karim Ali | last post by:
Hi, I would really appreciate help on this. I have a script (s1.py) which I would like to call from another script (s2.py). No problem there. The first issue is that s1.py has a command line...
3
11674
by: OD | last post by:
Hello, Is it possible with sqlserver to call a sql script from another sql script, like @ in oracle ? Thanks, Olivier
0
7027
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7019
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7067
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
4463
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2980
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2970
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
555
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.