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


Groups > comp.lang.python > #80462

Re: Python modules

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: Python modules
Date 2014-11-10 08:36 -0500
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-86BB5A.08362410112014@news.panix.com> (permalink)
References <i0h06a9pj8h3olo5rnrgc64i7ckpvtvti6@4ax.com>

Show all headers | View raw


In article <i0h06a9pj8h3olo5rnrgc64i7ckpvtvti6@4ax.com>,
 Steve Hayes <hayesstw@telkomsa.net> wrote:

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

Yes, this is a good idea.  Breaking your program down into modules, each 
of which does a small set of closely related things, makes it easier to 
manage.  You can test each module in isolation.  When you look at your 
version control log, you can see just the changes which apply to just 
that module.  When somebody new joins the team, they can learn about 
each module one at a time.

None of this is specific to Python.  Good software engineering practice 
is to break large applications into manageable pieces.  The vocabulary 
may change from language to language (module, package, class, library, 
dll, etc), but the basic concept is the same.

> But I understand that Python is an interpreted language, and 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?

Yes, exactly.  When you deploy your application someplace, you need to 
include all the things it depends on.  In the simple case of a few 
python files (say, a main program and a few modules that you're 
written), the easiest thing to do might be to just clone your source 
repository on the other machine and run it directly from that.  Another 
possibility would be to package up all the files in some sort of archive 
(tar, zip, whatever) and unpack that wherever you need it.

You will also have to set up a correct environment.  This usually means 
having an appropriate version of Python already installed, plus whatever 
third-party modules you use.

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