next up previous contents index
Next: V.1 Python examples Up: V. FeResPost Python bindings Previous: V. FeResPost Python bindings   Contents   Index

Subsections

V.0 Introduction

FeResPost is also distributed as a Python compiled library.

In general, the class names, their methods and attributes (properties), the parameters of these methods and attributes are the same as those available in the FeResPost ruby extension. The user is referred to Parts I, II, III and IV to find information on the use of the different classes and methods. In most cases, the information given there is sufficient to use the Python extension.


V.0.1 Accessing the Python extension

Typically, one imports the FeResPost Classes and Modules with a statement as:

    from FeResPost import *
Note however that it works only if the different environment variables have been initialized correctly. Typically, in our Windows examples, this is done through the batch files that are used to launch the example scripts, and the following variables are generally initialized:
    set LIB=
    set INCLUDE=
    set PYTHONPATH=D:/SHARED/FERESPOST/SRC/OUTPUTS/PYTHON/PYTHON_27
    set PATH=C:/NewProgs/PYTHON/PYTHON_27;C:/NewProgs/MINGW/bin
Note that we add the directory containing GNU compiler executables in ``PATH'' environment variable. This is necessary because some of the libraries delivered with GNU compiler are needed to run the python extension.

(Of course the different paths you will initialize will have to be adapted to you peculiar installation, and to the version of Python you are using.)


V.0.2 Python versus ruby

Most of the differences of FeResPost Python and ruby libraries are directly related to the differences of the two languages, which are very similar as far as the different language concepts are concerned. Therefore, the adaptation of ruby examples to Python language should not be very difficult.

One highlights below some differences between Python and ruby extensions that are related to specific programmatic aspects of the two different systems.


V.0.2.1 Creating class instances

New instances of the FeResPost classes are obtained by calling the corresponding class constructor:

   ...
   from FeResPost import *
   ...
   db=NastranDb()
   ...


V.0.2.2 Associative containers and Arrays

The Python ``list'' object corresponds to ruby ``Array'', and the Python ''Dictionary'' corresponds to ruby ``Hash'' objects. One remarks however that the Python dictionary keys cannot be ``list'' objects. When this problem occurs, the ruby Array should be converted in a Python tuple instead of a Python list.


V.0.2.3 Iterators

It is not possible to define several iterators in a given class in Python. Therefore, several special ``Iterator'' classes have been created in Python library. They are returned by the different FeResPost classes as is done for the COM component.

Let us illustrate it by an example... Consider the ``each_ply'' iterator defined in ClaLam class of FeResPost ruby extension. With the ruby extension, the iteration on the plies of a laminate may be performed as follows:

    ...
    lam.each_ply do |plyDescr|
        ...
    end
    ...
With Python, the code becomes:
    ...
    for ply in lam.iter_ply():
        ...
    ...
One could also write:
    ...
    x=lam.iter_ply()
    for ply in x:
        ...
    ...
As in the FeResPost ruby extension, each iterator method name starts with ``each_'', correspondingly, the Python methods returning an Iterator object have a name that starts with ``iter_''. The correspondence between ruby extension methods and COM component methods is obvious: ``each_ply'' becomes ``iter_ply'', ``each_material'' becomes ``iter_material'',...


V.0.2.4 ``nil'' arguments

With FeResPost ruby extension, an optional argument can be set to ``nil'' when not provided. The ``nil'' argument is to be replaced by ``None'' value in Python.


next up previous contents index
Next: V.1 Python examples Up: V. FeResPost Python bindings Previous: V. FeResPost Python bindings   Contents   Index
FeResPost User Manual Version 4.4.2 (2018/01/01)