import and scope inconsistency?

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

    import and scope inconsistency?

    I would be very grateful for help on the following.

    I have the following modules in a program. Names changed to protect the
    innocent.

    1.Simulation
    2.Branches
    3.MyFiles

    I import Branches, Myfiles and the publicly available module Numeric
    inside Simulation.

    Branches and MyFiles both contain class definitions.

    I can call MyFiles methods inside methods of the Brances classes.
    I cannot call Numeric methods inside methods of the Brances classes.

    1. I was surprised I could call MyFiles methods in Branches methods.
    2. Since I was used to using modules imported in the parent module I was
    surprised I couldn't use Numeric methods.

    What's going on?

    Thanks
    Jim O'Donnell
  • Heiko Wundram

    #2
    Re: import and scope inconsistency?

    Am Montag, 4. April 2005 12:23 schrieb Jim:[color=blue]
    > I can call MyFiles methods inside methods of the Brances classes.
    > I cannot call Numeric methods inside methods of the Brances classes.
    >
    > 1. I was surprised I could call MyFiles methods in Branches methods.
    > 2. Since I was used to using modules imported in the parent module I was
    > surprised I couldn't use Numeric methods.[/color]

    1. I can't answer you this one without looking at the actual code, but

    2. You can never call any methods/classes which you imported in a "parent"
    module (actually, there's no such motion as parent module, as each module has
    its own namespace, and references to this namespace may appear anywhere else
    in another module).

    In case this worked sometime ago and you didn't explicitly import the module
    in the "child" module, you silently did something like the following:

    Mod1.py
    -------

    import Numeric
    import Mod2

    # Put the namespace (module object) in another namespace
    Mod2.Numeric = Numeric

    <blah>


    Mod2.py
    -------

    <blah>


    What you need for your simulation program is probably something like the
    following:

    Simulation.py
    -------------

    import MyFiles
    import Branches
    import Numeric

    print MyFiles.Branche s is Branches # True
    print MyFiles.Numeric is Numeric # True
    print Branches.Numeri c is Numeric # True


    MyFiles.py
    ----------

    import Branches
    import Numeric

    print Branches.Numeri c is Numeric # True


    Branches.py
    -----------

    import Numeric


    HTH!

    --
    --- Heiko.
    listening to: aenima_13_aenim a.mp3
    see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.1 (GNU/Linux)

    iD8DBQBCURv9f0b pgh6uVAMRArqpAJ 934gNxmcJsFwUEs wjdJ/fupC3CQgCdEKBS
    ZONr0a90q5iQeqO 46XWepXs=
    =WQk5
    -----END PGP SIGNATURE-----

    Comment

    • Heiko Wundram

      #3
      Re: import and scope inconsistency?

      You're putting a Reply-To header in your posts to the mailing-list, but the
      Reply-To address bounces.

      Please correct: on't put in a Reply-To header, or at least put in some address
      that doesn't bounce.

      --
      --- Heiko.
      listening to: aenima_15_Third Eye.mp3
      see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/

      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.4.1 (GNU/Linux)

      iD8DBQBCURxgf0b pgh6uVAMRAuvcAJ 9FYHQKGmQ5ZvOhP QlUN05uNOnyrwCe Mmon
      Caju8HMcfsRkclA 1yuJ0QQ0=
      =VSHb
      -----END PGP SIGNATURE-----

      Comment

      • Jim

        #4
        Re: import and scope inconsistency?

        Heiko Wundram wrote:[color=blue]
        > You're putting a Reply-To header in your posts to the mailing-list, but the
        > Reply-To address bounces.
        >
        > Please correct: on't put in a Reply-To header, or at least put in some address
        > that doesn't bounce.
        >[/color]
        Thanks

        Comment

        Working...