[Cython] preferable way to replace a class

Brian Blais bblais at gmail.com
Tue Apr 7 21:29:11 CEST 2009


On Apr 7, 2009, at 15:05 , Lev Givon wrote:

> Received from Brian Blais on Tue, Apr 07, 2009 at 02:48:51PM EDT:
>> I am writing a tool to do some neural simulation, where I have  
>> several
>> different neuron groups, which are defined as python classes.  Is  
>> there a
>> preferred way to write a cython-only replacement such that the end- 
>> user
>> sees no difference?  What I mean is that they should be able to do:
>>
>> import sim
>>
>> n1=sim.NeuronGroup1(5)
>>
>> sim.run_sim([n1])
>>
>> and if the cython version exists, use that one (for both the neuron
>> group and the function to run the simulation), otherwise use the  
>> python
>> one.
>>
>>
> You could give the cython and python modules slightly different names
> (e.g., sim_cython and sim_python) and create a wrapper module (called
> sim) that contains the following code:
>
> try:
>     from sim_cython import *
> except ImportError:
>     from sim_python import *
>

Thanks!  Now, if not every class is implemented in sim_cython, should  
I do:

from sim_python import *
try:
     from sim_cython import *
except ImportError:
     pass


		thanks,

			bb

--
Brian Blais
bblais at gmail.com
http://web.bryant.edu/~bblais

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://codespeak.net/pipermail/cython-dev/attachments/20090407/1950955d/attachment.htm 


More information about the Cython-dev mailing list