Newbie: how to write modules without C

  • Thread starter Maarten van Reeuwijk
  • Start date
M

Maarten van Reeuwijk

I want to extend python with a framework for reading, manipulating and
visualising CFD data. Basically I want to have an environment in which I
can quickly and interactively produce results, and Python with SciPy seems
to be an ideal start.

However, the only references I can find about writing modules talk about
using C, and that's exactly what I DON'T want to do. I don't need any
low-level operations, just handy classes that understand my file-format and
wrap SciPy features etc.

So my questions are:
1) Is it necessary to resort to C when writing modules or can you use normal
Python?
2) How do you load a Python script into a python session?
3) Can various python scripts be combined into a module?

Thanks in advance!
 
I

Irmen de Jong

Maarten said:
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:
?

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top