Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7668

Re: break in a module

Date 2011-06-15 00:02 -0400
From Dave Angel <davea@ieee.org>
Subject Re: break in a module
References (2 earlier) <mailman.240.1308093309.11593.python-list@python.org> <qaWdnQmQzemLaWrQnZ2dnUVZ5vidnZ2d@giganews.com> <mailman.247.1308099095.11593.python-list@python.org> <87k4cnswt9.fsf@benfinney.id.au> <BANLkTinaxP039xcOvshXZZUoV4b3zxhKjg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.253.1308110548.11593.python-list@python.org> (permalink)

Show all headers | View raw


On 01/-10/-28163 02:59 PM, Eric Snow wrote:
> <snip>
>
> Unfortunately not.  Most of this line of thinking is the result of
> looking at import functionality in different ways, including with
> regards to the problem of modules getting imported twice (once as
> __main__).  I've been doing work on multi-file modules, custom module


Watch out for that importing of the original script.  Doing that has 
many risks, only one of which is the problem of the two names.

In fact, any time you have mutual imports, you run a certain risk, if 
the modules involved have any code that's not inside defs.  It's not 
well defined what order the initialisation happens, so you may wind up 
calling code in another module that's not really there yet.

The module import tree should be strictly hierarchical, without cycles. 
  if you need stuff from the __main__, pass it to the other module, 
don't let the other module peek back over your shoulder.

In the case of a module importing things from your script, the solution 
is pretty simple.  Move the needed code elsewhere, and import it both 
from your script and from the other module.

DaveA


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: break in a module Ethan Furman <ethan@stoneleaf.us> - 2011-06-14 16:28 -0700
  Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-14 16:51 -0700
    Re: break in a module Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-14 18:51 -0600
      Re: break in a module Ben Finney <ben+python@benfinney.id.au> - 2011-06-15 11:33 +1000
        Re: break in a module Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-14 20:21 -0600
          Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 15:09 -0700
        Re: break in a module Dave Angel <davea@ieee.org> - 2011-06-15 00:02 -0400
      Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 15:07 -0700
        Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-17 09:27 +1000
          Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 16:29 -0700
            Re: break in a module Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-16 18:00 -0600
            Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-17 10:01 +1000
              Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 18:13 -0700
                Re: break in a module Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 19:17 -0700
                Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 21:21 -0700
                Re: break in a module Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-16 22:53 -0600
        Re: break in a module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-17 00:48 +0000
          Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-17 10:57 +1000
            Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 18:21 -0700
              Re: break in a module Ethan Furman <ethan@stoneleaf.us> - 2011-06-16 19:11 -0700
              Re: break in a module Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-16 19:58 -0600
                Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 21:24 -0700
                Re: break in a module Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-16 22:50 -0600
                Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-16 22:20 -0700
                Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-17 15:56 +1000
                Re: break in a module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-17 06:00 +0000
                Re: break in a module Erik Max Francis <max@alcyone.com> - 2011-06-17 00:09 -0700
                Re: break in a module Cameron Simpson <cs@zip.com.au> - 2011-06-18 12:36 +1000
                Re: break in a module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-18 03:50 +0000
                Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-18 14:31 +1000
                Re: break in a module Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-18 04:49 +0000
                Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-18 15:06 +1000
                Re: break in a module Cameron Simpson <cs@zip.com.au> - 2011-06-21 20:04 +1000
                Re: break in a module Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-17 00:25 -0600
    Re: break in a module Chris Angelico <rosuav@gmail.com> - 2011-06-15 11:33 +1000

csiph-web