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


Groups > comp.lang.python > #26779

Re: I thought I understood how import worked...

Date 2012-08-09 15:52 +1000
From Cameron Simpson <cs@zip.com.au>
Subject Re: I thought I understood how import worked...
References <87hasehvfu.fsf@benfinney.id.au>
Newsgroups comp.lang.python
Message-ID <mailman.3094.1344491553.4697.python-list@python.org> (permalink)

Show all headers | View raw


On 08Aug2012 14:14, Ben Finney <ben+python@benfinney.id.au> wrote:
| Cameron Simpson <cs@zip.com.au> writes:
| > All of you are saying "two names for the same module", and variations
| > thereof. And that is why the doco confuses.
| >
| > I would expect less confusion if the above example were described as
| > _two_ modules, with the same source code.
| 
| That's not true though, is it? It's the same module object with two
| different references, I thought.

No. They're two in-memory module instantiations with distinct module
names. ISTR that when this got me I had imported the a module in one
place with its full name and elsewhere with a bad relative reference; I
forget the details now. But anyway, that got me the same module code
loaded twice, distinctly named.

| Also, even if what you say were true, “source code” implies the module
| was loaded from source code, when Python allows loading modules with no
| source code available. So that implication just seems to be inviting
| different confusion.

Please let's nail one thing first. We can always quibble about the term "source
code" to prefer "source code or byte code" or something of that ilki,
later.

But the confusion comes from calling these things the "same module".
Which breaks the "modules are only loaded once" mental image.

The confusion would often be avoided if the doco took the line that
it is two modules because they were obtained using two names. Their
original might be the same physical/logical place (such as a module
source code file), but the end result is two modules.

The point is that the "module" term would be better if it referred to the
in-memory Python module, and didn't do double time as meaning the
(typically) source file from which the Python code comes.

Cheers,
-- 
Cameron Simpson <cs@zip.com.au>

We had the experience, but missed the meaning.  - T.S. Eliot

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


Thread

I thought I understood how import worked... Roy Smith <roy@panix.com> - 2012-08-07 09:18 -0400
  Re: I thought I understood how import worked... Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-07 13:52 +0000
    Re: I thought I understood how import worked... Roy Smith <roy@panix.com> - 2012-08-07 08:25 -0700
      Re: I thought I understood how import worked... Paul Rubin <no.email@nospam.invalid> - 2012-08-07 08:53 -0700
      Re: I thought I understood how import worked... Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-07 17:54 +0000
    Re: I thought I understood how import worked... Cameron Simpson <cs@zip.com.au> - 2012-08-08 08:47 +1000
      Re: I thought I understood how import worked... Roy Smith <roy@panix.com> - 2012-08-07 19:05 -0400
      Re: I thought I understood how import worked... Ben Finney <ben+python@benfinney.id.au> - 2012-08-08 14:14 +1000
        Re: I thought I understood how import worked... Laszlo Nagy <gandalf@shopzeus.com> - 2012-08-08 08:40 +0200
        Re: I thought I understood how import worked... Roy Smith <roy@panix.com> - 2012-08-08 09:12 -0400
        Re: I thought I understood how import worked... Cameron Simpson <cs@zip.com.au> - 2012-08-09 15:52 +1000
  Re: I thought I understood how import worked... Ben Finney <ben+python@benfinney.id.au> - 2012-08-07 23:55 +1000
    Re: I thought I understood how import worked... Laszlo Nagy <gandalf@shopzeus.com> - 2012-08-07 16:14 +0200
    Re: I thought I understood how import worked... Roy Smith <roy@panix.com> - 2012-08-07 08:32 -0700
      Re: I thought I understood how import worked... Terry Reedy <tjreedy@udel.edu> - 2012-08-07 13:15 -0400
  Re: I thought I understood how import worked... Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-07 15:10 +0100
  Re: I thought I understood how import worked... Terry Reedy <tjreedy@udel.edu> - 2012-08-07 12:49 -0400
  Re: I thought I understood how import worked... Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-07 18:44 +0100
  Re: I thought I understood how import worked... Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-08-08 10:47 +0200

csiph-web