Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'symbols': 0.07; 'python': 0.08; 'be:': 0.09; 'namespace': 0.09; 'variables.': 0.09; 'am,': 0.12; 'def': 0.13; 'cc:addr:python-list': 0.15; '"from': 0.16; 'symbolic': 0.16; 'wrote:': 0.16; 'solution.': 0.17; 'wed,': 0.17; 'subject:Question': 0.19; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; 'maybe': 0.21; 'feb': 0.22; 'header:In-Reply-To:1': 0.22; 'received:209.85.212.46': 0.23; 'received:mail- vw0-f46.google.com': 0.23; 'defined': 0.24; 'math': 0.24; 'cc:2**0': 0.25; 'module': 0.26; 'function': 0.27; 'import': 0.27; 'message-id:@mail.gmail.com': 0.28; 'example': 0.28; 'importing': 0.28; 'cc:addr:python.org': 0.29; 'chris': 0.30; 'received:209.85.212': 0.34; 'something': 0.35; 'but': 0.37; 'received:google.com': 0.37; 'could': 0.37; 'received:209.85': 0.38; 'think': 0.38; 'possible.': 0.39; "what's": 0.39; 'define': 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'alternative': 0.65; 'subject:name': 0.67; 'obtained': 0.80; 'sender:addr:chris': 0.84; 'alone.': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=nJwFUN3Sw+KRbRmGaDv20aHixhmqZc6OQIXOrrb7FBo=; b=cfquxWM8Ak1TF/oBe7JFJbuT9ee+Foz4xMa/+mTUBcv56xkxWYJQBImBEsTlO33WOL ESM51ZLkNr/INhNyUgcaMYtXR8ifazhKNHYrjFK4TCFyl5BQqXPTRQqKjknUp1RhsbyB UjnAnaT/R/xp8EJISD9w1a3PsmxWagg9GXI/M= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: <20120201181117.5d35dddc@bigfoot.com> References: <20120201181117.5d35dddc@bigfoot.com> Date: Wed, 1 Feb 2012 09:38:59 -0800 X-Google-Sender-Auth: y6LBGnBYTSWelX2KvNcmVCbWHp8 Subject: Re: Question about name scope From: Chris Rebert To: Olive Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1328117942 news.xs4all.nl 6895 [2001:888:2000:d::a6]:55283 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19728 On Wed, Feb 1, 2012 at 9:11 AM, Olive wrote: > I am learning python and maybe this is obvious but I have not been able > to see a solution. What I would like to do is to be able to execute a > function within the namespace I would have obtained with =C2=A0from > import * > > For example if I write: > > def f(a): > =C2=A0 =C2=A0 =C2=A0 =C2=A0return sin(a)+cos(a) > > I could then do: > > from math import * > > f(5) > > But I have polluted my global namespace with all what's defined in > math. I would like to be able to do something like "from math import *" > at the f level alone. > > The main reason for this is the sympy module for CAS (computer algebra). > It reimplement a lot of functions and define all the letters as symbolic > variables. Writing sympy. everywhere is inconvenient. > Importing all the symbols in the global namespace would lead to name > clash. It would be nice if I could import all the sympy names but for a > given function only. Don't think that's possible. Best alternative I can think of would be: import sympy as s def f(a): return s.sin(a) + s.cos(a) Cheers, Chris