Difference between a library and a module...

akameswaran at gmail.com akameswaran at gmail.com
Tue Mar 7 10:09:38 EST 2006


I'm not 100% sure what is a library in python.  Your example above is
importing a module.

Someone else can correct me, but I use libraries to refer to underlying
c/c++ code that is required for the python modules to function.  So in
pure python you are really only dealing with modules.

string.replace() I'm 90% sure is a function in the string module.
However something like this:
foo = "bar"
foo.Capitalize()

bar.capitalize is executing a method.  Actually at this point
string.replace() may be a method as well, I don't know for sure as I
haven't inspected the string module's code.

Read some intro to OOP, for a better understanding, but the main
difference between a function and a method, is that a method is
associated with some class or object.  In Python it's really only
objects (even class is an object)  Hence when I created the string
object foo, and executed Capitalize() it was a method on the string
object. the same thing as a function might look something like:

# defining a function
def capitalize(inStr)
  #do stuff  here to capitalize the string
  return outStr

foo = capitalize("bar")

hope this helps.




More information about the Python-list mailing list