Imports

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

    #1

    Imports

    I am working with a tool called maxQ that generates jython scripts.
    The tool runs in

    C:\maxq\bin.


    Rather than clutter up bin I want to put the scripts and other .py
    scripts in

    c:\maxq\bin\tes tScripts.


    When doing so the scripts need to import from

    c:\maxq\jython, but can't find the modules.


    I tried adding c:\maxq\jython to the environment variable pythonpath
    but to no avail. Perhaps I missed it in Rossum's tutorial but is there
    a std prgrammatic way to specify a module directory?

    Could you, would you, recommend a text or another webpage for learning
    more (much more) about python?

    Thanx,

    gtb

  • kyosohma@gmail.com

    #2
    Re: Imports

    On Mar 20, 1:31 pm, "gtb" <goodTweetieB.. .@hotmail.comwr ote:
    I am working with a tool called maxQ that generates jython scripts.
    The tool runs in
    >
    C:\maxq\bin.
    >
    Rather than clutter up bin I want to put the scripts and other .py
    scripts in
    >
    c:\maxq\bin\tes tScripts.
    >
    When doing so the scripts need to import from
    >
    c:\maxq\jython, but can't find the modules.
    >
    I tried adding c:\maxq\jython to the environment variable pythonpath
    but to no avail. Perhaps I missed it in Rossum's tutorial but is there
    a std prgrammatic way to specify a module directory?
    >
    Could you, would you, recommend a text or another webpage for learning
    more (much more) about python?
    >
    Thanx,
    >
    gtb
    I typically just import sys and then do a
    sys.path.append (directoryPath) . This basically makes whatever modules
    in that path available at run time. If you need a beginners reference
    book, I recommend "Beginning Python" by Hetland. "Python Programming
    for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
    get into the internals of the language like Hetland does. Once you're
    a snake charmer too, you can "graduate" to the "Programmin g Python"
    book by Lutz.

    Mike

    Comment

    • gtb

      #3
      Re: Imports

      On Mar 20, 1:51 pm, kyoso...@gmail. com wrote:
      On Mar 20, 1:31 pm, "gtb" <goodTweetieB.. .@hotmail.comwr ote:
      >
      >
      >
      I am working with a tool called maxQ that generates jython scripts.
      The tool runs in
      >
      C:\maxq\bin.
      >
      Rather than clutter up bin I want to put the scripts and other .py
      scripts in
      >
      c:\maxq\bin\tes tScripts.
      >
      When doing so the scripts need to import from
      >
      c:\maxq\jython, but can't find the modules.
      >
      I tried adding c:\maxq\jython to the environment variable pythonpath
      but to no avail. Perhaps I missed it in Rossum's tutorial but is there
      a std prgrammatic way to specify a module directory?
      >
      Could you, would you, recommend a text or another webpage for learning
      more (much more) about python?
      >
      Thanx,
      >
      gtb
      >
      I typically just import sys and then do a
      sys.path.append (directoryPath) . This basically makes whatever modules
      in that path available at run time. If you need a beginners reference
      book, I recommend "Beginning Python" by Hetland. "Python Programming
      for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
      get into the internals of the language like Hetland does. Once you're
      a snake charmer too, you can "graduate" to the "Programmin g Python"
      book by Lutz.
      >
      Mike
      Something else going on then, does the directory path need to be the
      full path or will it search sub-directories?

      Traceback (most recent call last):
      File "C:\maxq-0.98\bin\testSc ripts\compactLo gin.py", line 2, in
      <module>
      from CompactTest import CompactTest
      File "c:\maxq-0.98\jython\Com pactTest.py", line 2, in <module>
      from java.lang import *
      ImportError: No module named java.lang

      Thanks for the book recommendations .

      gtb

      Comment

      • kyosohma@gmail.com

        #4
        Re: Imports

        On Mar 20, 1:59 pm, "gtb" <goodTweetieB.. .@hotmail.comwr ote:
        On Mar 20, 1:51 pm, kyoso...@gmail. com wrote:
        >
        >
        >
        On Mar 20, 1:31 pm, "gtb" <goodTweetieB.. .@hotmail.comwr ote:
        >
        I am working with a tool called maxQ that generates jython scripts.
        The tool runs in
        >
        C:\maxq\bin.
        >
        Rather than clutter up bin I want to put the scripts and other .py
        scripts in
        >
        c:\maxq\bin\tes tScripts.
        >
        When doing so the scripts need to import from
        >
        c:\maxq\jython, but can't find the modules.
        >
        I tried adding c:\maxq\jython to the environment variable pythonpath
        but to no avail. Perhaps I missed it in Rossum's tutorial but is there
        a std prgrammatic way to specify a module directory?
        >
        Could you, would you, recommend a text or another webpage for learning
        more (much more) about python?
        >
        Thanx,
        >
        gtb
        >
        I typically just import sys and then do a
        sys.path.append (directoryPath) . This basically makes whatever modules
        in that path available at run time. If you need a beginners reference
        book, I recommend "Beginning Python" by Hetland. "Python Programming
        for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
        get into the internals of the language like Hetland does. Once you're
        a snake charmer too, you can "graduate" to the "Programmin g Python"
        book by Lutz.
        >
        Mike
        >
        Something else going on then, does the directory path need to be the
        full path or will it search sub-directories?
        >
        Traceback (most recent call last):
        File "C:\maxq-0.98\bin\testSc ripts\compactLo gin.py", line 2, in
        <module>
        from CompactTest import CompactTest
        File "c:\maxq-0.98\jython\Com pactTest.py", line 2, in <module>
        from java.lang import *
        ImportError: No module named java.lang
        >
        Thanks for the book recommendations .
        >
        gtb
        Usually, the sys.path.append will allow Python to search the
        subfolders too, but I have noticed that sometimes it doesn't if you
        use UNC paths. I don't use jython, so maybe there's another way to fix
        this that is more specific to that implementation of Python?

        Mike

        Comment

        • gtb

          #5
          Re: Imports

          On Mar 20, 2:25 pm, kyoso...@gmail. com wrote:
          On Mar 20, 1:59 pm, "gtb" <goodTweetieB.. .@hotmail.comwr ote:
          >
          >
          >
          On Mar 20, 1:51 pm, kyoso...@gmail. com wrote:
          >
          On Mar 20, 1:31 pm, "gtb" <goodTweetieB.. .@hotmail.comwr ote:
          >
          I am working with a tool called maxQ that generates jython scripts.
          The tool runs in
          >
          C:\maxq\bin.
          >
          Rather than clutter up bin I want to put the scripts and other .py
          scripts in
          >
          c:\maxq\bin\tes tScripts.
          >
          When doing so the scripts need to import from
          >
          c:\maxq\jython, but can't find the modules.
          >
          I tried adding c:\maxq\jython to the environment variable pythonpath
          but to no avail. Perhaps I missed it in Rossum's tutorial but is there
          a std prgrammatic way to specify a module directory?
          >
          Could you, would you, recommend a text or another webpage for learning
          more (much more) about python?
          >
          Thanx,
          >
          gtb
          >
          I typically just import sys and then do a
          sys.path.append (directoryPath) . This basically makes whatever modules
          in that path available at run time. If you need a beginners reference
          book, I recommend "Beginning Python" by Hetland. "Python Programming
          for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
          get into the internals of the language like Hetland does. Once you're
          a snake charmer too, you can "graduate" to the "Programmin g Python"
          book by Lutz.
          >
          Mike
          >
          Something else going on then, does the directory path need to be the
          full path or will it search sub-directories?
          >
          Traceback (most recent call last):
          File "C:\maxq-0.98\bin\testSc ripts\compactLo gin.py", line 2, in
          <module>
          from CompactTest import CompactTest
          File "c:\maxq-0.98\jython\Com pactTest.py", line 2, in <module>
          from java.lang import *
          ImportError: No module named java.lang
          >
          Thanks for the book recommendations .
          >
          gtb
          >
          Usually, the sys.path.append will allow Python to search the
          subfolders too, but I have noticed that sometimes it doesn't if you
          use UNC paths. I don't use jython, so maybe there's another way to fix
          this that is more specific to that implementation of Python?
          >
          Mike
          Thanks for the sys.path.append info. Turns out maxq cranks thing up
          with java ( I should have seen it). The sys.path.append does
          everything it supposed to do.

          gtb

          Comment

          • Gabriel Genellina

            #6
            Re: Imports

            En Tue, 20 Mar 2007 16:25:41 -0300, <kyosohma@gmail .comescribió:
            Usually, the sys.path.append will allow Python to search the
            subfolders too, but I have noticed that sometimes it doesn't if you
            use UNC paths. I don't use jython, so maybe there's another way to fix
            this that is more specific to that implementation of Python?
            Python does not search subfolders during a normal import. Perhaps you were
            thinking about subpackages?

            --
            Gabriel Genellina

            Comment

            • 7stud

              #7
              Re: Imports

              On Mar 20, 12:51 pm, kyoso...@gmail. com wrote:
              I typically just import sys and then do a
              sys.path.append (directoryPath) . This basically makes whatever modules
              in that path available at run time. If you need a beginners reference
              book, I recommend "Beginning Python" by Hetland. "Python Programming
              for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
              get into the internals of the language like Hetland does. Once you're
              a snake charmer too, you can "graduate" to the "Programmin g Python"
              book by Lutz.
              >
              Mike
              I can't access any modules using the sys.path.append () method. Here
              is my directory structure:

              /
              ----Users
              ---------Me
              ------------2testing
              ------------------dir1
              ---------------------test1.py
              ---------------------programs_python
              -----------------------------testA.py

              testA.py:
              ------------------------
              def show(x):
              print x

              if __name__ == "__main__":
              show("hello")
              ------------------------

              test1.py:
              ------------------------
              import sys

              sys.path.append ("/Users/Me/2testing/dir1/programs_python ")
              testA.show("hel lo")
              ------------------------

              command:
              ~/2testing/dir1$ python test1.py

              output:
              Traceback (most recent call last):
              File "test1.py", line 4, in ?
              testA.show("hel lo")
              NameError: name 'testA' is not defined

              Any idea how to do that?

              Comment

              • 7stud

                #8
                Re: Imports

                On Mar 20, 6:33 pm, "7stud" <bbxx789_0...@y ahoo.comwrote:
                On Mar 20, 12:51 pm, kyoso...@gmail. com wrote:
                >
                I typically just import sys and then do a
                sys.path.append (directoryPath) . This basically makes whatever modules
                in that path available at run time. If you need a beginners reference
                book, I recommend "Beginning Python" by Hetland. "Python Programming
                for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
                get into the internals of the language like Hetland does. Once you're
                a snake charmer too, you can "graduate" to the "Programmin g Python"
                book by Lutz.
                >
                Mike
                >
                I can't access any modules using the sys.path.append () method. Here
                is my directory structure:
                >
                /
                ----Users
                ---------Me
                ------------2testing
                ------------------dir1
                ---------------------test1.py
                ---------------------programs_python
                -----------------------------testA.py
                >
                testA.py:
                ------------------------
                def show(x):
                print x
                >
                if __name__ == "__main__":
                show("hello")
                ------------------------
                >
                test1.py:
                ------------------------
                import sys
                >
                sys.path.append ("/Users/Me/2testing/dir1/programs_python ")
                testA.show("hel lo")
                ------------------------
                >
                command:
                ~/2testing/dir1$ python test1.py
                >
                output:
                Traceback (most recent call last):
                File "test1.py", line 4, in ?
                testA.show("hel lo")
                NameError: name 'testA' is not defined
                >
                Any idea how to do that?
                Hmmm...I got it to work like this:

                test1.py:
                ---------
                import sys
                sys.path.append ("/Users/Me/2testing/dir1/programs_python ")

                import testA
                testA.show("hel lo")

                Comment

                • Steve Holden

                  #9
                  Re: Imports

                  7stud wrote:
                  On Mar 20, 6:33 pm, "7stud" <bbxx789_0...@y ahoo.comwrote:
                  >On Mar 20, 12:51 pm, kyoso...@gmail. com wrote:
                  >>
                  >>I typically just import sys and then do a
                  >>sys.path.appe nd(directoryPat h). This basically makes whatever modules
                  >>in that path available at run time. If you need a beginners reference
                  >>book, I recommend "Beginning Python" by Hetland. "Python Programming
                  >>for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
                  >>get into the internals of the language like Hetland does. Once you're
                  >>a snake charmer too, you can "graduate" to the "Programmin g Python"
                  >>book by Lutz.
                  >>Mike
                  >I can't access any modules using the sys.path.append () method. Here
                  >is my directory structure:
                  >>
                  >/
                  >----Users
                  >---------Me
                  >------------2testing
                  >------------------dir1
                  >---------------------test1.py
                  >---------------------programs_python
                  >-----------------------------testA.py
                  >>
                  >testA.py:
                  >------------------------
                  >def show(x):
                  > print x
                  >>
                  >if __name__ == "__main__":
                  > show("hello")
                  >------------------------
                  >>
                  >test1.py:
                  >------------------------
                  >import sys
                  >>
                  >sys.path.appen d("/Users/Me/2testing/dir1/programs_python ")
                  >testA.show("he llo")
                  >------------------------
                  >>
                  >command:
                  >~/2testing/dir1$ python test1.py
                  >>
                  >output:
                  >Traceback (most recent call last):
                  > File "test1.py", line 4, in ?
                  > testA.show("hel lo")
                  >NameError: name 'testA' is not defined
                  >>
                  >Any idea how to do that?
                  >
                  Hmmm...I got it to work like this:
                  >
                  test1.py:
                  ---------
                  import sys
                  sys.path.append ("/Users/Me/2testing/dir1/programs_python ")
                  >
                  import testA
                  testA.show("hel lo")
                  >
                  That's how it's s'posed to work. You still have to explicitly import the
                  modules you want - the sys.path just tells Python where to look for them.

                  regards
                  Steve
                  --
                  Steve Holden +44 150 684 7255 +1 800 494 3119
                  Holden Web LLC/Ltd http://www.holdenweb.com
                  Skype: holdenweb http://del.icio.us/steve.holden
                  Recent Ramblings http://holdenweb.blogspot.com

                  Comment

                  Working...