[Fwd: [Pipet Devel] more nice interfaces]

Konrad Hinsen hinsen at cnrs-orleans.fr
Mon Mar 1 05:16:02 EST 1999

> I have a c-module with functions bb_sequence.reverse,
> bb_sequence.complement etc. and I want to create a class in python called
> bb_sequence ... the original question was about how to add the c-module
> into the class ... but I think I am going to rename the c-functions and
> wrap them in the python code.

That's the best solution. You *could* write some C-level type and
inherit from it in a Python class by using the ExtensionClass
package, but there's no point unless you really want/need to
provide a generally useful C type.

> I'd like to evaluate variables with function names, like:
> for i in ["reverse" "coplement" "antiparallel"]:
>     print i,": ",bb_sequence.i

That just needs a slight rewrite:

for i in ["reverse" "coplement" "antiparallel"]:
    print i,": ", getattr(bb_sequence, i)

getattr() works for method names as well, it simply returns a method
object, which can be called like a function. From my current
undestanding of your original Tcl example, the Python equivalent would

for i in ["reverse" "coplement" "antiparallel"]:
    print i,": ", getattr(bb_sequence, i)(seq)

Konrad Hinsen                            | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-
Rue Charles Sadron                       | Fax:  +33-
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais

More information about the Pipet-Devel mailing list