Python Programming for Biology: Bioinformatics and Beyond



Download 7,75 Mb.
Pdf ko'rish
bet438/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   434   435   436   437   438   439   440   441   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

Writing faster modules

At one time doing anything especially intensive in Python was not practical. Fortunately

though,  the  main  implementation  of  Python  is  itself  written  in  C  and  has  a  specified,

although not extensively documented, way of interfacing C code with the Python world.

Thus the idea is to write numerically intensive code in C (or C++, or even Fortran suitably

wrapped  in  C)  and  then  call  that  routine  from  inside  Python.  As  we  discuss  in  the  last

section of this chapter, one way to do this is by using the ctypes module. This lets Python

create C-compatible data types and call C functions, which is especially useful to interact

with  established  C  libraries.  However,  in  the  initial  instance  we  will  make  the  language

interface in C. In theory you can also access Python data types directly in C, given that’s

what  they  are  written  in,  but  the  most  useful  approach  is  to  keep  most  of  the  C  code

general  (i.e.  not  Python-specific)  and  then  to  wrap  a  thin  layer  of  specialised  interface

code  in  C  that  connects  the  Python  world  to  your  C  code.  This  interface  layer  is  often

described as boilerplate code, referring to the fact that you have to write the same kind of

interface for each module. Accordingly, and as illustrated in

Figure 27.2

, when a specific

C  function  gets  called  from  the  Python  code,  the  Python  variables  are  converted  into

variables  that  your  C  code  understands,  the  compiled  C  code  is  called,  the  returned

variable is converted to a Python data type and the function passes that back to the Python

world. You can even use a tool to write this boilerplate code, the best known being SWIG

(Simplified Wrapper and Interface Generator).





Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   434   435   436   437   438   439   440   441   ...   514




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish