Newbie: how to write modules without C

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Thu Jan 15 08:07:20 EST 2004


Maarten van Reeuwijk wrote:

> 1) Is it necessary to resort to C when writing modules or can you use normal
> Python?

Absolutely not! I'm wondering what you've read that made you think this.
That text should be rewritten to be more clear: you write
*extension modules* in C (or C++). 'normal' modules are just Python files.

For example: Python's standard library is hundreds of modules written in
pure Python... (and also a bunch of extension modules written in C, for
various reasons).

> 2) How do you load a Python script into a python session?

Not sure what you mean here? What's wrong with:

 >>> import MaartensNiceModule

?

> 3) Can various python scripts be combined into a module?

Perhaps you're confusing the concepts of 'script', 'module' and 'package'.
A python 'module' is just a script actually. A 'package' is a special
directory that can contain lots of modules and sub packages.
A Python module can contain lots of classes, function definitions,
and other code. It is not constrained to a single class implementation
like for instance Java has. It's closer to the way C/C++ work with
their source files. And Python packages are related to C++ namespaces,
but more powerful.

I strongly recommend you read chapter 6, Modules, of the tutorial:
http://www.python.org/doc/current/tut/node8.html

Good luck!

--Irmen de Jong.



More information about the Python-list mailing list