python script question
Michael Stenner
mstenner at phy.duke.edu
Mon Oct 21 12:39:12 EDT 2002
On Tue, Oct 22, 2002 at 01:31:04AM +1000, Ken wrote:
> Hi all, just like to ask if python CGI script can be mix with python Shell
> script?
>
> I.e. if:
> file1 is CGI (#!/usr/local/bin/python)
> and file2 is shell script (#!/bin/sh)
>
> can I have "import file2" inside file1 and use the functions inside file2?
Short (and pretty darned accurate) answer: no.
You can run any shell COMMAND (including shell scripts) from within a
python program via system or popen, or whatever. You won't easily be
able to call a function from within a shell script, though.
You could make "script wrappers" for all of those functions. If you
have a master shell script that acts like a library, defining several
functions, but executing none of them, then you could make several
wrappers, each of them a script... like so:
#!/bin/sh
source master.sh
# function foo is defined in master.sh
foo $@
Then, you can call this file (foo.sh) via system from within python.
> Also, does the shell script have *.py extension?
Shell scripts usually have .sh extensions, but on unix, the extension
exists only for the user's convenience. It usually has no relevance
for the os.
-Michael
--
Michael Stenner Office Phone: 919-660-2513
Duke University, Dept. of Physics mstenner at phy.duke.edu
Box 90305, Durham N.C. 27708-0305
More information about the Python-list
mailing list