Difference between a library and a module...

Laszlo Zsolt Nagy gandalf at designaproduct.biz
Tue Mar 7 16:16:43 CET 2006


sophie_newbie wrote:

>OK this might seem like a retarded question, but what is the difference
>between a library and a module?
>
>If I do:
>
>import string
>
>am I importing a module or a library?
>  
>
I'm not a guru, but... I think that modules are things that live inside 
the Python language. In the above case, you are importing a Python 
module. I think that a library is something that resides on the file 
system and contains code. But it can be anything, and it exists outside 
a Python program. I have the feeling that a library is usually lives in 
compiled form, while a python module can be anything that can be 
'import'-ed (py file, pyd file or an so file...)

>And if i do string.replace() am I using a module or a function or a
>method or what?
>  
>
What you call here is:  "string.replace". In the standard string module, 
replace is a function. But if "string" refers to a custom module, then 
string.replace could be a class or an object (or any callable) as well.

By the way, modules are not callable at all.
Methods can only be called with an object.
Class methods can be called with a class.

Well, a module is itself a special object, called the 'module object'. 
Module objects have no class, and they cannot be instantiated or called.

http://docs.python.org/ref/types.html#l2h-105


I hope this helps.

  Laszlo




More information about the Python-list mailing list