next up previous contents index
Next: VI. FeResPost as COM Up: V. FeResPost Python bindings Previous: V.0 Introduction   Contents   Index

Subsections


V.1 Python examples

As the adaptation from ruby to Python is straightforward, the current chapter is also very short. We only highlight some of the differences related to ruby and Python language differences.


V.1.1 Iterators

The first example of an iterator with Python library is in ``PYTHON/EX02/printGroups.py'' and reads as follows:

for groupName in db.iter_groupName():
    grp = db.getGroupCopy(groupName)
    nodesNbr = grp.NbrElements
    elementsNbr = grp.NbrNodes
    mpcsNbr = grp.NbrMpcs
    coordNbr = grp.NbrCoordSys
    print("%20s%10d%10d%10d%10d"%(groupName,nodesNbr,elementsNbr,
        mpcsNbr,coordNbr))
Note:


V.1.2 SQLite examples

The use of SQLite library is explained in Python documentation. With FeResPost, the BLOB object returned by ``toBlob'' method must be converted into a Python buffer using the corresponding function:

for lcName in lcNames:
    for resName in resNames:
        results=db.getAttachmentResults(xdbFileName,lcName,scNames,resName)
        if (results):
            for key,res in results.iteritems():
                print key
                sqldb.execute(
                    "insert or replace into dynam_results_1 values(?,?,?,?,?,?,?,?,?,?)",
                    [lcName,key[1],resName,res.TensorOrder,
                    res.getIntId(0),res.getIntId(1),
                    res.getRealId(0),res.getRealId(1),
                    res.Size,buffer(res.toBlob())])
            sqldb.commit()
        else:
            print "NO FOR" + lcName + resName
Note that the call to ``buffer'' method seems necessary with versions 2.* of Python, but must be removed for version 3.*.


next up previous contents index
Next: VI. FeResPost as COM Up: V. FeResPost Python bindings Previous: V.0 Introduction   Contents   Index
FeResPost User Manual Version 4.4.2 (2018/01/01)