Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.032 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.13; 'slightly': 0.19; 'subject:Question': 0.19; 'header:In-Reply-To:1': 0.22; 'math': 0.24; 'import': 0.27; 'needed,': 0.28; 'print': 0.29; 'lock': 0.30; 'threads.': 0.30; 'does': 0.32; 'header:User-Agent:1': 0.33; 'to:addr:python-list': 0.33; 'approach.': 0.34; 'function.': 0.34; 'header:X-Complaints-To:1': 0.34; 'trouble': 0.35; 'received:org': 0.37; 'using': 0.37; 'received:de': 0.39; 'received:78': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'type': 0.60; 'cause': 0.66; 'subject:name': 0.67 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Christian Heimes Subject: Re: Question about name scope Date: Wed, 01 Feb 2012 18:50:53 +0100 References: <20120201181117.5d35dddc@bigfoot.com> <4F297824.1000202@davea.name> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: f048097078.adsl.alicedsl.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20120129 Thunderbird/10.0 In-Reply-To: <4F297824.1000202@davea.name> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328118667 news.xs4all.nl 6852 [2001:888:2000:d::a6]:43088 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19730 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