5. Examples of use#

The standard use of this procedure is:

POURSUITE ()
Python does not save the functions and classes defined in the main file (it simply remembers in which Python module they were defined). So this is the case with the code_aster command file.

To use functions or classes and find them in continuation, you must define them in an external module:

- Let the userpkg/usermod.py module be:

def pyfunc (x) :return x*2


- In the first set of commands, we would do:

DEBUT () from userpkg import usermodform = FORMULE ((NOM_PARA ='X', VALE ='pyfunc (X) ', pyfunc=usermod.pyfunc) assert form (2) == 2) == 4 FIN ()


- Then:

POURSUITE (PAR_LOT =' NON ') assert form (2) == 4 FIN ()

To do this, simply add the userpkg directory name to the study.

It should be understood that, during the review, Python will try to import the userpkg.usermod module. He must therefore find it in the same place.

In addition, by importing this module, Python executes the instructions found in it.

For this reason, it is not recommended to create concepts in the main body of an imported module (because they will be created at each import and will clutter up the database). It must be done in functions that will only be performed on demand.