Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19728

Re: Question about name scope

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 <chris@rebertia.com>
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 <clp2@rebertia.com>
To Olive <diolu@bigfoot.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5312.1328117942.27778.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Wed, Feb 1, 2012 at 9:11 AM, Olive <diolu@bigfoot.com> 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  from <module>
> import *
>
> For example if I write:
>
> def f(a):
>        return 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.<function> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Question about name scope Olive <diolu@bigfoot.com> - 2012-02-01 18:11 +0100
  Re: Question about name scope Rick Johnson <rantingrickjohnson@gmail.com> - 2012-02-01 09:21 -0800
  Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 09:43 -0800
  Re: Question about name scope Dave Angel <d@davea.name> - 2012-02-01 12:36 -0500
    Re: Question about name scope Mel Wilson <mwilson@the-wire.com> - 2012-02-01 13:47 -0500
      Re: Question about name scope Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-01 14:49 -0700
      Re: Question about name scope Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-01 15:38 -0700
      Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 14:24 -0800
      Re: Question about name scope Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-01 16:00 -0700
      Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 15:08 -0800
      Re: Question about name scope Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-01 16:47 -0700
      Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 14:53 -0800
        Re: Question about name scope Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-02 00:34 +0000
      Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 15:59 -0800
      Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 15:41 -0800
      Re: Question about name scope Ethan Furman <ethan@stoneleaf.us> - 2012-02-01 15:51 -0800
  Re: Question about name scope Chris Rebert <clp2@rebertia.com> - 2012-02-01 09:38 -0800
  Re: Question about name scope Christian Heimes <lists@cheimes.de> - 2012-02-01 18:50 +0100

csiph-web