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


Groups > comp.lang.python > #80772

Re: Two locations for module struct ?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sub': 0.09; 'subject:module': 0.09; 'val': 0.09; 'ast': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:Two': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; 'module': 0.19; '>>>': 0.22; 'import': 0.22; 'putting': 0.22; 'header:User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'code': 0.31; 'struct': 0.31; 'skip:m 30': 0.32; 'but': 0.35; 'there': 0.35; 'should': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'even': 0.60; 'places': 0.64; 'wave': 0.74; 'struct.': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Two locations for module struct ?
Date Fri, 14 Nov 2014 17:51:35 +0100
Organization None
References <54661ba8$0$2906$426a74cc@news.free.fr>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bd879c.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15823.1415983912.18130.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415983912 news.xs4all.nl 2831 [2001:888:2000:d::a6]:38203
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80772

Show key headers only | View raw


ast wrote:

> In module wave there is a sub module struct.
> You can call function pack() with:
> 
> import wave
> val = wave.struct.pack(...)
> 
> but the same function can be called with:
> 
> import struct
> val = struct.pack(...)
> 
> Is it exactly the same module in both location ?

You can answer that yourself:

>>> import struct, wave
>>> struct is wave.struct
True

> Why putting struct in two places ?

Assumming your code is part of a module called mymodule.py

> import wave
> val = wave.struct.pack(...)

> import struct
> val = struct.pack(...)

you can now also do

import mymodule
val = mymodule.struct.pack(...)

or even

val = mymodule.wave.struct.pack(...)

Do you see the pattern? You should ;)

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


Thread

Two locations for module struct ? "ast" <nomail@invalid.com> - 2014-11-14 16:11 +0100
  Re: Two locations for module struct ? Chris Angelico <rosuav@gmail.com> - 2014-11-15 03:24 +1100
  Re: Two locations for module struct ? Peter Otten <__peter__@web.de> - 2014-11-14 17:51 +0100
    Re: Two locations for module struct ? "ast" <nomail@invalid.com> - 2014-11-14 19:12 +0100
  Re: Two locations for module struct ? Terry Reedy <tjreedy@udel.edu> - 2014-11-14 16:47 -0500

csiph-web