[SciPy-user] How to solve name mangling ?

Ryan May rmay@ou....
Fri Jun 8 08:08:07 CDT 2007


Stef Mientki wrote:
> 
>>   
> well I don't ;-)
> But that might have to do with my lousy organization.
> 
> Here's what I have right now,
> from a friend I got a library,
> with the message,
> add this line at the top of your code,
> and you can use everthing in the library:
> 
>     from my_friends_module import *
> 
> In my friends module there is the following code
> 
>     from  array  import  array
> 
> Now I get my N-less "array".
> So I probably shouldn't have followed my friends advice,
> and I should just have written
> 
>     import my_friends_module
> 
> Another solution could be, but don't know if it's safe enough
> 
>     from my_friends_module import *
>     # and always as the last import do my own
>     from scipy import array

Why not this:

    from my_friends_module import foo,bar
    from scipy import array

Which (if the apis) are compatible would allow a drop in replacement
latter of:

    from my_friends_module2 import foo,bar
    from numpy import array

with no other code changes. I'm assuming we're talking about long term
maintained code, and not just a quick script.  For that case I do the:

import numpy as N
import pylab as P

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma



More information about the SciPy-user mailing list