[Tutor] definition of a library

dman dsh8290@rit.edu
Tue, 19 Mar 2002 22:46:29 -0600


On Tue, Mar 19, 2002 at 08:34:50PM -0500, Erik Price wrote:
| I've seen the word "library" used in the context of software code since 
| before I can remember.  I've never really known what it is.  So I 
| googled...
| 
| ...according to webopedia.internet.com, a library has two definitions:
| 
| (1) A collection of files.
| 
| (2) In programming, a library is a collection of precompiled routines 
| that a program can use. The routines, sometimes called modules, are 
| stored in object format. Libraries are particularly useful for storing 
| frequently used routines because you do not need to explicitly link them 
| to every program that uses them. The linker automatically looks in 
| libraries for routines that it does not find elsewhere. In MS-Windows 
| environments, library files have a .DLL extension.
| 
| I'm referring to the second definition, when I ask my question -- are 
| there libraries in Python? 

As it says, a library is
    a collection of routines that a program can use

| Does the Python binary know where to search for this code, or do I
| need to import it as I do with modules?  Are libraries in Python
| generally in already-compiled form (as described in the second
| definition) or are they generally raw source code?

In python, libraries can be written in Python, C, or C++ (and possibly
some other language, but I haven't seen them).  If they are python,
then they are usually distributed in source form since the interpreter
will automatically byte-compile them.  If they are C or C++ then they
must be compiled into a "shared libary" (.so on *nix, .dll on 'doze).
The interpreter knows how to load .py[co]? files itself, and locates
them via $PYTHONPATH and sys.path.  The C function dlopen() allows a
(C) program to link and load a .so at runtime.  Thus the interpreter
can load an extension module without being recompiled.

When dealing with python, people commonly use the terms "module" or
"package", but they basically mean the same thing as "library".

Since we have decided that a module or a package is a library, yes you
do need to import them :-).

HTH,
-D

-- 

I can do all things through Christ who strengthens me.
        Philippians 4:13