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


Groups > comp.lang.python > #80451

Re: Python modules

Path csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'tutorial': 0.03; 'third- party': 0.04; 'importing': 0.05; 'interpreter': 0.05; 'subject:Python': 0.06; 'distributing': 0.07; 'parties.': 0.07; 'steve': 0.09; 'collapsed': 0.09; 'imported': 0.09; 'interpreted': 0.09; 'machines.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:modules': 0.09; 'python': 0.11; 'language,': 0.12; 'wrote': 0.14; '(barring': 0.16; 'bytecode': 0.16; 'finney': 0.16; 'hayes': 0.16; 'hierarchy,': 0.16; 'modules,': 0.16; 'modules.': 0.16; 'path.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sorts': 0.16; 'essential': 0.16; 'language': 0.16; 'library': 0.18; 'module': 0.19; 'code,': 0.22; 'import': 0.22; 'install': 0.23; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'compilation': 0.24; 'copied': 0.24; 'source': 0.25; 'compiled': 0.26; 'header:X -Complaints-To:1': 0.27; 'installed': 0.27; '(this': 0.29; 'topic': 0.29; 'needed.': 0.30; 'relative': 0.30; 'along': 0.30; 'idea,': 0.31; 'writes:': 0.31; 'yes.': 0.31; 'covered': 0.32; 'run': 0.32; 'another': 0.32; 'url:python': 0.33; 'running': 0.33; 'third': 0.33; 'actual': 0.34; 'but': 0.35; 'right?': 0.36; 'done': 0.36; 'doing': 0.36; 'url:org': 0.36; 'application': 0.37; 'operating': 0.37; 'two': 0.37; 'step': 0.37; 'manager': 0.38; 'ben': 0.38; 'question,': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'does': 0.39; 'structure': 0.39; 'to:addr:python.org': 0.39; 'system.': 0.39; 'received:org': 0.40; 'how': 0.40; 'future': 0.60; 'url:3': 0.61; "you're": 0.61; 'places': 0.64; 'different': 0.65; 'default': 0.69; 'distinguish': 0.84; 'execution.': 0.84; 'received:125': 0.84; 'step,': 0.84; 'directly.': 0.95
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ben Finney <ben+python@benfinney.id.au>
Subject Re: Python modules
Date Mon, 10 Nov 2014 16:12:07 +1100
References <i0h06a9pj8h3olo5rnrgc64i7ckpvtvti6@4ax.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host jigong.madmonks.org
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)
Cancel-Lock sha1:0sYJZ1xahrlmj1I5ceWWfUEH3U0=
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.15614.1415596346.18130.python-list@python.org> (permalink)
Lines 58
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415596346 news.xs4all.nl 2890 [2001:888:2000:d::a6]:43023
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80451

Show key headers only | View raw


Steve Hayes <hayesstw@telkomsa.net> writes:

> I have a book on Python that advocates dividing programs into modules,
> and importing them when needed.

Which book is this? (This is not essential to your question, but it
might help to gauge your broader learning environment.)

> I can understand doing that in a compiled language, where different
> modules can be imported from all sorts of places when the program is
> compiled.

Python is a compiled language; when you run a Python program a necessary
step is to compile the Python source to a bytecode for actual execution.

Usually, the compilation step is done dynamically; but (barring
contrived examples) it is always done prior to running the program.

> But I understand that Python is an interpreted language

The two are not mutually exclusive. The Python interpreter works with
compiled Python code, it does not execute the source directly.

> If I wrote a program in Python like that, and wanted to run it on
> another computer, how would it find all the modules to import at
> run-time, unless I copied the whole directory structure over to the
> other computer?

That's the idea, yes. You need to distinguish between:

* The standard library: installed along with the Python interpreter when
  you install that, and available on the default module search path.

* Third-party modules: installed using your package manager (ideally by
  the operating system package manager), again to a location already
  part of the default module search path on your system.

* Modules specific to the application you're writing: Keep these in a
  known hierarchy, and use the distribution tools to package them to
  keep them together when distributing to oher machines.

Use abolute import for standard library and third-party modules. Use
relative import for application-private modules.

This ensures your aplication's private modules don't conflict with
current or future names of modules from the standard library or third
parties.

You are working through the Python tutorial step by step, right?
<URL:https://docs.python.org/3/tutorial/> This topic is covered when you
learn about modules <URL:https://docs.python.org/3/tutorial/modules.html>.

-- 
 \       “I am amazed, O Wall, that you have not collapsed and fallen, |
  `\            since you must bear the tedious stupidities of so many |
_o__)                  scrawlers.” —anonymous graffiti, Pompeii, 79 CE |
Ben Finney

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


Thread

Python modules Steve Hayes <hayesstw@telkomsa.net> - 2014-11-10 06:55 +0200
  Re: Python modules Deepfriedice <Deepfriedice@openmailbox.org> - 2014-11-10 14:55 +1000
  Re: Python modules Ben Finney <ben+python@benfinney.id.au> - 2014-11-10 16:12 +1100
    Re: Python modules Steve Hayes <hayesstw@telkomsa.net> - 2014-11-10 08:58 +0200
      Re: Python modules Ben Finney <ben+python@benfinney.id.au> - 2014-11-10 18:48 +1100
  Re: Python modules Roy Smith <roy@panix.com> - 2014-11-10 08:36 -0500
    Re: Python modules Chris Angelico <rosuav@gmail.com> - 2014-11-11 00:49 +1100
  Re: Python modules Will Acheson <willyach07@gmail.com> - 2014-11-11 12:06 -0800
    Re: Python modules Ben Finney <ben+python@benfinney.id.au> - 2014-11-12 09:18 +1100

csiph-web