472,791 Members | 1,132 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 software developers and data experts.

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 4070
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
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
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
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
by: priya.tweety | last post by:
How to call a js file from another js file?
10
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
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
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
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
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
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.