[Tutor] definition of a library
alan.gauld@bt.com
alan.gauld@bt.com
Wed, 20 Mar 2002 17:59:14 -0000
> On Tuesday, March 19, 2002, at 11:46 PM, dman wrote:
> > In python, libraries can be written in Python, C, or C++
> (and possibly some other language, but I haven't seen them).
FWIW
I usually distinguish between modules and libraries (despite
the definition that was quited earlier!) Libraries can be an
amalgam of several modules. A module is a unit of reusable code.
A library is a physical file that contains reusable or shared
code, and that may include multiple modules. Its a subtle but
sometimes important distinction (and one not recognised
by UML for those who care :-).
> Since I'm not quite ready to learn C or C++ (maybe tomorrow :), I can
> just assume that if a C or C++ library is intended to be
> embedded within Python programs, then it has already been
> compiled appropriately?
Yes, usually. Occasionally you may get a library in source form
in which case you need to comile it. In most cases you just use it.
> > 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
>
> Let me stop you for a minute for a clarification -- does this
> mean that any C programs need to be called with dlopen()?
Yes but its the python interpreter code that does it not yours.
When you import a module thats a C module the interpreter loads
it via this function(I assume - I haven't looked!)
> Has this been specially written so as not to require the dlopen()
> function, or is it because it's not a .so file?
It does exist in a .so somewhere I think but it *does* need
dlopen() its just handled by Python when you import cpickle.
The good news is that regardless of whether a module is
implemented in Python or in C you just import it and Python
does the rest(provided you've installed it in the right
place and told Python where to find it of course!)
HTH
Alan G.