How to call a script from another?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christian

    #1

    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
  • Jaime Wyant

    #2
    Re: How to call a script from another?

    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 <christian@spam .no> wrote:[color=blue]
    > 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
    >[/color]

    Comment

    • Scott David Daniels

      #3
      Re: How to call a script from another?

      Jaime Wyant wrote:[color=blue]
      > 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...[/color]
      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.scri pt; script.zopescri pt.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
      scott.daniels@a cm.org

      Comment

      • Christian

        #4
        Re: How to call a script from another?

        Thanks guy's, you have opened my eyes and made my next step a whole lot
        easier.


        Chris

        Comment

        • Dennis Lee Bieber

          #5
          Re: How to call a script from another?

          On Thu, 13 Oct 2005 16:29:37 +0200, Christian <christian@spam .no>
          declaimed the following in comp.lang.pytho n:
          [color=blue]
          > 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.
          >[/color]
          Pardon? If you can't execute "shell scripts", how do you intend to
          execute the python script to execute the other python script?
          [color=blue]
          > So my question is:
          > How do I call a .py script from another .py script?
          > (Writing the rest - I hope - is piece of cake ;-) ).
          >[/color]
          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("pyth on myOtherPython.p y")

          {If you have a new enough Python release, there is a subprocess module
          that has a bit more capability}
          [color=blue]
          > (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.)
          >[/color]
          OTOH, if the script is designed as an importable module, you could

          import myOtherPython
          myOtherPython.m OP_main_entry_p oint()

          --[color=blue]
          > =============== =============== =============== =============== == <
          > wlfraed@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
          > wulfraed@dm.net | Bestiaria Support Staff <
          > =============== =============== =============== =============== == <
          > Home Page: <http://www.dm.net/~wulfraed/> <
          > Overflow Page: <http://wlfraed.home.ne tcom.com/> <[/color]

          Comment

          Working...