Re: Strange namespace issue

2020-08-11 Thread Chris Angelico
On Wed, Aug 12, 2020 at 12:03 PM Lele Gaifax wrote: > But I see this is somewhat fragile, and wonder about a proper fix, but isn't > that a reasonable usage of the "locals" argument to exec()? > I'm not sure. Passing a locals argument to eval() I have sometimes done, but never exec(). I've always

Re: Strange namespace issue

2020-08-11 Thread Lele Gaifax
Chris Angelico writes: > Interesting. You're passing an empty globals and a non-empty locals > (the second and third arguments to exec, respectively). Is that > deliberate? By the look of this code, it's meant to be at global scope > (as if it's the top level code in a module), which is best done

Re: Strange namespace issue

2020-08-10 Thread Chris Angelico
On Tue, Aug 11, 2020 at 5:44 AM Lele Gaifax wrote: > > Hi all, > > today I faced an issue that, although very easy to fix, left me wondering > about what causes it. > > The context is an application that execute small scripts coming from an > external source (say, a database). The application firs

Strange namespace issue

2020-08-10 Thread Lele Gaifax
Hi all, today I faced an issue that, although very easy to fix, left me wondering about what causes it. The context is an application that execute small scripts coming from an external source (say, a database). The application first compile the script, then execute it passing it some values: in t

Re: namespace issue, Python vs numpy min/max problem

2010-11-14 Thread Robert Kern
On 2010-11-14 17:37 , Gregory Ewing wrote: Steven D'Aprano wrote: It only becomes your problem if you have advised people that the right way to use your module is with import *. And if you're advising people to do that, it would be an extremely good idea to give your functions different names

Re: namespace issue, Python vs numpy min/max problem

2010-11-14 Thread Gregory Ewing
Steven D'Aprano wrote: It only becomes your problem if you have advised people that the right way to use your module is with import *. And if you're advising people to do that, it would be an extremely good idea to give your functions different names so that they don't conflict with the builti

Re: namespace issue, Python vs numpy min/max problem

2010-11-13 Thread Steven D'Aprano
On Sat, 13 Nov 2010 11:41:09 -0800, dmitrey wrote: > hi all, > I have the following problem: > I have overloaded "max" function in my module (FuncDesigner); it works > like following: > if some data in arguments is of type "oofun" then my function works, > elseware numpy.max() is used. > > Now th

Re: namespace issue, Python vs numpy min/max problem

2010-11-13 Thread Terry Reedy
On 11/13/2010 2:41 PM, dmitrey wrote: hi all, I have the following problem: I have overloaded "max" function in my module (FuncDesigner); it works like following: if some data in arguments is of type "oofun" then my function works, elseware numpy.max() is used. Now the problem: suppose someone w

Re: namespace issue, Python vs numpy min/max problem

2010-11-13 Thread Ben James
On 13/11/2010 19:55, dmitrey wrote: Well, I think I have found an appropriate solution. Regards, D. Hi Dmitrey, Would you mind briefly describing your solution? Thanks, Ben -- http://mail.python.org/mailman/listinfo/python-list

Re: namespace issue, Python vs numpy min/max problem

2010-11-13 Thread dmitrey
Well, I think I have found an appropriate solution. Regards, D. -- http://mail.python.org/mailman/listinfo/python-list

namespace issue, Python vs numpy min/max problem

2010-11-13 Thread dmitrey
hi all, I have the following problem: I have overloaded "max" function in my module (FuncDesigner); it works like following: if some data in arguments is of type "oofun" then my function works, elseware numpy.max() is used. Now the problem: suppose someone writes from FuncDesigner import * ... a =

Re: Namespace issue

2007-05-23 Thread 7stud
On May 23, 12:20 pm, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > As per my understanding, the bad part is that on every call of the method > FetchData(), an import would be done. > > To not let that happen, I can put the import into __init__(). But when I put > in there, I get a NameError saying

Re: Namespace issue

2007-05-23 Thread 7stud
On May 23, 12:20 pm, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > As per my understanding, the bad part is that on every call of the method > FetchData(), an import would be done. > > To not let that happen, I can put the import into __init__(). But when I put > in there, I get a NameError saying

Re: Namespace issue

2007-05-23 Thread 7stud
On May 23, 12:20 pm, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > As per my understanding, the bad part is that on every call of the method > FetchData(), an import would be done. > > To not let that happen, I can put the import into __init__(). But when I put > in there, I get a NameError saying

Re: Namespace issue

2007-05-23 Thread kyosohma
On May 23, 1:20 pm, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > Hi, > > I need a little help in understanding how Namespaces and scoping works with > Classes/Functions in Python. > > Here's my code: > class FetchData: > def __init__(self, dataTypes=["foo", "bar", "spam"], archive=False): > >

Re: Namespace issue

2007-05-23 Thread kyosohma
On May 23, 1:20 pm, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote: > Hi, > > I need a little help in understanding how Namespaces and scoping works with > Classes/Functions in Python. > > Here's my code: > class FetchData: > def __init__(self, dataTypes=["foo", "bar", "spam"], archive=False): > >

Namespace issue

2007-05-23 Thread Ritesh Raj Sarraf
Hi, I need a little help in understanding how Namespaces and scoping works with Classes/Functions in Python. Here's my code: class FetchData: def __init__(self, dataTypes=["foo", "bar", "spam"], archive=False): self.List = [] self.Types = dataTypes if

Re: namespace issue

2006-04-14 Thread Daniel Nogradi
> def _gn(x): > return x.upper() > > great_name = _gn > > class myclass: > def mymethod(self, great_name=False): > if great_name: > return _gn('something') > else: > return 'something' > >>> def great_name(x): > ... return x.upper() > ... > >>

Re: namespace issue

2006-04-13 Thread Steven D'Aprano
On Thu, 13 Apr 2006 22:59:52 +0200, Daniel Nogradi wrote: > I would like to give the same name to a keyword argument of a class > method as the name of a function, with the function and the class > living in the same namespace and the class method using the > aforementioned function. That's a pr

Re: namespace issue

2006-04-13 Thread Steven Bethard
Daniel Nogradi wrote: > I would like to give the same name to a keyword argument of a class > method as the name of a function, with the function and the class > living in the same namespace and the class method using the > aforementioned function. So far I've been unsuccesfully trying to go > alon

Re: namespace issue

2006-04-13 Thread Daniel Nogradi
Ooops, there was a typo in my previous mail: > in the hope of the del statement only removing the local variable util ^ the above line should be: in the hope of the del statement only removing the lo

namespace issue

2006-04-13 Thread Daniel Nogradi
I would like to give the same name to a keyword argument of a class method as the name of a function, with the function and the class living in the same namespace and the class method using the aforementioned function. So far I've been unsuccesfully trying to go along these lines: def great_name(