looking for a simple way to load a program from another python program..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric_Dexter@msn.com

    #1

    looking for a simple way to load a program from another python program..

    I was looking for a simple way to load a simple python program from
    another python program.

    I tried

    os.system(cabel )

    The file name is cabel.py a csound instrument editor..

    The error I am getting is

    Traceback (most recent call last):
    File "C:\Python24\Li b\site-packages\boa-constructor\tes t of
    snake\Frame1.py ", line 212, in OnCabelItems0Me nu
    os.system(cabel )
    NameError: global name 'cabel' is not defined
    Localisation of messages is disabled, using default language.
    time resolution is 279.365 ns

    This is with cabel in the current directory. I have managed to use
    import to run it but it will only do it once. I may be able to use the
    exec commands but I don't want to exit the program I am using only to
    run other programs and then exit. I would also perfer that cabel is in
    it's own directory.

    thanks in advance for any help

    Storm Pages provides you with 25 MB of FREE web space to build and host a website about whatever topic you choose. Stormpages includes many useful hosting features and web tools to build a website or web page.


  • Simon Forman

    #2
    Re: looking for a simple way to load a program from another python program..

    Eric_Dexter@msn .com wrote:
    I was looking for a simple way to load a simple python program from
    another python program.
    >
    I tried
    >
    os.system(cabel )
    >
    The file name is cabel.py a csound instrument editor..
    >
    The error I am getting is
    >
    Traceback (most recent call last):
    File "C:\Python24\Li b\site-packages\boa-constructor\tes t of
    snake\Frame1.py ", line 212, in OnCabelItems0Me nu
    os.system(cabel )
    NameError: global name 'cabel' is not defined
    Localisation of messages is disabled, using default language.
    time resolution is 279.365 ns
    >
    This is with cabel in the current directory. I have managed to use
    import to run it but it will only do it once. I may be able to use the
    exec commands but I don't want to exit the program I am using only to
    run other programs and then exit. I would also perfer that cabel is in
    it's own directory.
    >
    thanks in advance for any help
    >
    http://www.stormpages.com/edexter/csound.html
    Read the docs: os.system() takes a string. You're calling it with an
    uninitialized variable name. Unless you have something like "cabel =
    'cabel'" somewhere before your call os.system() you can expect that
    error.

    "import cabel" will only work once because python's module import
    mechanism caches imported modules to save time when a script imports
    them more than once. To force the module to be reloaded use the reload
    function: "reload(cab el)"

    os.system() docs: http://docs.python.org/lib/os-process.html#l2h-1692
    (But see the subprocess module too:
    http://docs.python.org/lib/module-subprocess.html)

    Peace,
    ~Simon

    Comment

    • Caleb Hattingh

      #3
      Re: looking for a simple way to load a program from another python program..

      Hi Eric

      Check that ".py" and ".pyw" are in your PATHEXT environment variable
      (are you using Windows?). Then, if the folder that cabel is in is in
      your PATH environment variable, and the correct association for .py
      files is set up (i.e. they get run by python.exe),

      either
      os.system('cabe l')
      or
      os.system('cabe l.py')

      should work.

      Alternatively, you could not do any of those things, and run

      os.system('pyth on cabel.py')

      with 'cabel.py' in the same folder as the parent script, and that
      should work too, assuming that the path to your python executable is on
      the PATH environment variable.

      If you run other commands from python quite frequently, it is probably
      a good idea to look into the "os.popen" set of commands, for more
      flexibilty.

      Caleb

      Comment

      • Eric_Dexter@msn.com

        #4
        Re: looking for a simple way to load a program from another python program..


        Caleb Hattingh wrote:
        Hi Eric
        >
        Check that ".py" and ".pyw" are in your PATHEXT environment variable
        (are you using Windows?). Then, if the folder that cabel is in is in
        your PATH environment variable, and the correct association for .py
        files is set up (i.e. they get run by python.exe),
        >
        either
        os.system('cabe l')
        or
        os.system('cabe l.py')
        >
        should work.
        >
        Alternatively, you could not do any of those things, and run
        >
        os.system('pyth on cabel.py')
        >
        with 'cabel.py' in the same folder as the parent script, and that
        should work too, assuming that the path to your python executable is on
        the PATH environment variable.
        >
        If you run other commands from python quite frequently, it is probably
        a good idea to look into the "os.popen" set of commands, for more
        flexibilty.
        >
        Caleb
        import cabel and reload(cabel) seem to work fine. I am not sure why I
        am having trouble with os.system . Tells me it isn't a command.
        thanks for the help, I will look into os.popen to see what it does.
        would there be ay

        Comment

        • Eric_Dexter@msn.com

          #5
          Re: looking for a simple way to load a program from another python program..


          Caleb Hattingh wrote:
          Hi Eric
          >
          Check that ".py" and ".pyw" are in your PATHEXT environment variable
          (are you using Windows?). Then, if the folder that cabel is in is in
          your PATH environment variable, and the correct association for .py
          files is set up (i.e. they get run by python.exe),
          >
          either
          os.system('cabe l')
          or
          os.system('cabe l.py')
          >
          should work.
          >
          Alternatively, you could not do any of those things, and run
          >
          os.system('pyth on cabel.py')
          >
          with 'cabel.py' in the same folder as the parent script, and that
          should work too, assuming that the path to your python executable is on
          the PATH environment variable.
          >
          If you run other commands from python quite frequently, it is probably
          a good idea to look into the "os.popen" set of commands, for more
          flexibilty.
          >
          Caleb
          import cabel and reload(cabel) seem to work fine. I am not sure why I
          am having trouble with os.system, probily something to do with the
          path. Is one better than the other when it comes to distributing
          software?? Thanks for the help. Hopefully this message I get isn't
          anything important.. (I will have to look into os.popen later.

          Localisation of messages is disabled, using default language.
          time resolution is 279.365 ns

          Comment

          • Luis M. González

            #6
            Re: looking for a simple way to load a program from another python program..

            Try this:

            import os
            os.startfile('c abel.py')

            This should work with any program or file, not only python ones.

            Hope this helps,
            Luis

            Comment

            • AlbaClause

              #7
              Re: looking for a simple way to load a program from another python program..

              Eric_Dexter@msn .com wrote:
              I was looking for a simple way to load a simple python program from
              another python program.
              >
              I tried
              >
              os.system(cabel )
              >
              The file name is cabel.py a csound instrument editor..
              >
              The error I am getting is
              >
              Traceback (most recent call last):
              File "C:\Python24\Li b\site-packages\boa-constructor\tes t of
              snake\Frame1.py ", line 212, in OnCabelItems0Me nu
              os.system(cabel )
              NameError: global name 'cabel' is not defined
              Localisation of messages is disabled, using default language.
              time resolution is 279.365 ns
              >
              This is with cabel in the current directory. I have managed to use
              import to run it but it will only do it once. I may be able to use the
              exec commands but I don't want to exit the program I am using only to
              run other programs and then exit. I would also perfer that cabel is in
              it's own directory.
              >
              thanks in advance for any help
              >
              http://www.stormpages.com/edexter/csound.html
              I am new to Python coding myself, but I've found that the easiest way to
              start another script from within a script, is to use the
              execfile('filen ame.py') command.

              There may be better ways of loading other Python scripts -- better ways that
              I'm not yet aware of -- but execfile() works for me.


              --
              --
              There are several things that I will never be:
              * I will never be attracted to females.
              * I will never enjoy the company of others.
              Exactly how these realities bode for my enemy, is not of my concern.

              Comment

              • Gabriel Genellina

                #8
                Re: looking for a simple way to load a program from anotherpython program..

                At Sunday 13/8/2006 16:51, Eric_Dexter@msn .com wrote:
                I was looking for a simple way to load a simple python program from
                >another python program.
                >
                >I tried
                >
                >os.system(cabe l)
                >
                >The file name is cabel.py a csound instrument editor..
                >
                >NameError: global name 'cabel' is not defined
                Have you tried os.system("cabe l.py")



                Gabriel Genellina
                Softlab SRL





                _______________ _______________ _______________ _____
                Preguntá. Respondé. Descubrí.
                Todo lo que querías saber, y lo que ni imaginabas,
                está en Yahoo! Respuestas (Beta).
                ¡Probalo ya!


                Comment

                • Eric_Dexter@msn.com

                  #9
                  Re: looking for a simple way to load a program from another python program..


                  Gabriel Genellina wrote:
                  At Sunday 13/8/2006 16:51, Eric_Dexter@msn .com wrote:
                  >
                  I was looking for a simple way to load a simple python program from
                  another python program.

                  I tried

                  os.system(cabel )

                  The file name is cabel.py a csound instrument editor..

                  NameError: global name 'cabel' is not defined
                  >
                  Have you tried os.system("cabe l.py")
                  >
                  That did not seem to work, os.startfile worked great. I haven't tried
                  passing commands to csound with it yet but maybe os.sytem will work
                  better with that than it did python since I got the idea to use that to
                  pass arguments to them from a csound example. won't have time until
                  this weekend to try that though, or the exec(file)..



                  Storm Pages provides you with 25 MB of FREE web space to build and host a website about whatever topic you choose. Stormpages includes many useful hosting features and web tools to build a website or web page.


                  Comment

                  Working...