Question about name scope

Christian Heimes lists at cheimes.de
Wed Feb 1 12:50:53 EST 2012


Am 01.02.2012 18:36, schrieb Dave Angel:
> def f(a):
>     from math import sin, cos
>     return sin(a) + cos(a)
> 
> print f(45)
> 
> Does what you needed, and neatly.  The only name added to the global
> namspace is f, of type function.

I recommend against this approach. It's slightly slower and the global
import lock will cause trouble if you start using threads.

Christian




More information about the Python-list mailing list