Newbie: how to write modules without C

Discussion in 'Python' started by Maarten van Reeuwijk, Jan 15, 2004.

  1. 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!


    --
    ===================================================================
    Maarten van Reeuwijk Heat and Fluid Sciences
    Phd student dept. of Multiscale Physics
    www.ws.tn.tudelft.nl Delft University of Technology
    Maarten van Reeuwijk, Jan 15, 2004
    #1
    1. Advertising

  2. 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.
    Irmen de Jong, Jan 15, 2004
    #2
    1. Advertising

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


    This is exactly what I couldn't find before, thanks!

    --
    ===================================================================
    Maarten van Reeuwijk Heat and Fluid Sciences
    Phd student dept. of Multiscale Physics
    www.ws.tn.tudelft.nl Delft University of Technology
    Maarten van Reeuwijk, Jan 15, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Remy Cool
    Replies:
    1
    Views:
    419
    Remy Cool
    Aug 27, 2003
  2. Tobiah
    Replies:
    2
    Views:
    303
    Tobiah
    Sep 14, 2003
  3. Ben Weintraub

    Disabling modules using Modules/Setup

    Ben Weintraub, Sep 9, 2006, in forum: Python
    Replies:
    0
    Views:
    343
    Ben Weintraub
    Sep 9, 2006
  4. Rob Knop
    Replies:
    1
    Views:
    275
  5. Great Deals
    Replies:
    2
    Views:
    84
    peter pilsl
    Sep 24, 2003
Loading...

Share This Page