Re: Namespaces: memory vs 'pollution'

2019-07-23 Thread Ethan Furman
On 07/22/2019 08:12 PM, DL Neil wrote: On 22/07/19 9:40 PM, Thomas Jollans wrote: Just FYI, in the scientific Python community certain short abbreviations are the norm. Many modules have a ‘standard’ abbreviation that most people use, minimizing confusion. import numpy as np import matplotlib

Re: Namespaces: memory vs 'pollution'

2019-07-23 Thread Ethan Furman
On 07/22/2019 07:27 PM, DL Neil wrote: NameError conveys nothing to the user. PythonVersionError is more communicative - and speaks volumes to 'us'. The mainline code is something like: p = PythonEnvironment() try:     p.compatibility( ...spec... )    # eg must be Py3 not 2.n  

Re: Namespaces: memory vs 'pollution'

2019-07-23 Thread Thomas Jollans
On 23/07/2019 04.27, DL Neil wrote: > On 23/07/19 11:00 AM, Ethan Furman wrote: >> On 07/20/2019 05:02 PM, DL Neil wrote: >> >>> Upon closer inspection, I realised it didn't just fail; it failed >>> badly! Some silly, little, boy had imported the PythonEnvironment >>> class but failed to ALSO impor

Re: Namespaces: memory vs 'pollution'

2019-07-23 Thread Rhodri James
On 23/07/2019 03:27, DL Neil wrote: On 23/07/19 11:00 AM, Ethan Furman wrote: On 07/20/2019 05:02 PM, DL Neil wrote: Upon closer inspection, I realised it didn't just fail; it failed badly! Some silly, little, boy had imported the PythonEnvironment class but failed to ALSO import PythonVersio

Re: Namespaces: memory vs 'pollution'

2019-07-22 Thread DL Neil
On 22/07/19 9:40 PM, Thomas Jollans wrote: On 22/07/2019 07.06, DL Neil wrote: Current thoughts: import environment_module as em - so, even more of an abbreviation than suggested!? - I rarely need to write a long list of import statements, so there won't be many. - not normally using suc

Re: Namespaces: memory vs 'pollution'

2019-07-22 Thread DL Neil
On 23/07/19 11:00 AM, Ethan Furman wrote: On 07/20/2019 05:02 PM, DL Neil wrote: Upon closer inspection, I realised it didn't just fail; it failed badly! Some silly, little, boy had imported the PythonEnvironment class but failed to ALSO import PythonVersionError. So, the reported error was n

Re: Namespaces: memory vs 'pollution'

2019-07-22 Thread Thomas Jollans
On 22/07/2019 07.06, DL Neil wrote: > > Current thoughts: > > import environment_module as em > > - so, even more of an abbreviation than suggested!? > - I rarely need to write a long list of import statements, so there > won't be many. > - not normally using such abbreviations in my code, they

Re: Namespaces: memory vs 'pollution'

2019-07-22 Thread Ethan Furman
On 07/20/2019 05:02 PM, DL Neil wrote: Upon closer inspection, I realised it didn't just fail; it failed badly! Some silly, little, boy had imported the PythonEnvironment class but failed to ALSO import PythonVersionError. So, the reported error was not the expected exception! I don't under

Re: Namespaces: memory vs 'pollution'

2019-07-21 Thread DL Neil
On 22/07/19 5:30 AM, Roel Schroeven wrote: DL Neil schreef op 21/07/2019 om 2:02: How do you remember to from-import- 'everything' that is needed? ... > Upon closer inspection, I realised it didn't just fail; it failed badly! Some silly, little, boy had imported the PythonEnvironment class but

Re: Namespaces: memory vs 'pollution'

2019-07-21 Thread Roel Schroeven
DL Neil schreef op 21/07/2019 om 2:02: How do you remember to from-import- 'everything' that is needed? ... > Upon closer inspection, I realised it didn't just fail; it failed badly! Some silly, little, boy had imported the PythonEnvironment class but failed to ALSO import PythonVersionError. So,

Re: Namespaces: memory vs 'pollution'

2019-07-21 Thread Peter J. Holzer
On 2019-07-21 12:02:27 +1200, DL Neil wrote: > What do you do to (respecting purism) ensure 'everything' (necessary) is > imported (and nothing more), preferably without relying upon (faulty, in my > case) human-memory or reading through volumes of code/documentation? I write tests (not as consist

Re: Namespaces are one honking great idea

2016-07-09 Thread carlosjosepita
Hi all, although it doesn't fit the bill 100%, I sometimes use this extremely simple function as a decorator: def new(call): return call() For example: @new class MySingleton: x = 2 y = 2 def sum(self, x, y): return x + y @new def my_obj(): x = 2 y = 2 de

A nestedmodule decorator (Re: Namespaces are one honking great idea)

2016-07-05 Thread Gregory Ewing
Steven D'Aprano wrote: There's only so far I can go without support from the compiler. It turns out one can go surprisingly far. Here's something I cooked up that seems to meet almost all the requirements. The only shortcoming I can think of is that a nestedmodule inside another nestedmodule wo

Re: Namespaces are one honking great idea

2016-07-04 Thread Steven D'Aprano
On Tuesday 05 July 2016 13:47, Chris Angelico wrote: > On Tue, Jul 5, 2016 at 1:35 PM, Steven D'Aprano wrote: >>> If you push your code into a separate .py file, you can reference the >>> original module by importing it. Is that also the normal way to use >>> "outer" functions etc from inside a n

Re: Namespaces are one honking great idea

2016-07-04 Thread Chris Angelico
On Tue, Jul 5, 2016 at 1:35 PM, Steven D'Aprano wrote: >> If you push your code into a separate .py file, you can reference the >> original module by importing it. Is that also the normal way to use >> "outer" functions etc from inside a namespace? > > Good question! > > With the current implement

Re: Namespaces are one honking great idea

2016-07-04 Thread Steven D'Aprano
On Tue, 5 Jul 2016 12:58 pm, Chris Angelico wrote: > On Tue, Jul 5, 2016 at 12:34 PM, Steven D'Aprano > wrote: >> *** IF *** you are willing to push the code out into its own separate .py >> file, you can use a module and write your code in a more natural form: >> >> >> # module example.py >> var

Re: Namespaces are one honking great idea

2016-07-04 Thread Chris Angelico
On Tue, Jul 5, 2016 at 12:34 PM, Steven D'Aprano wrote: > *** IF *** you are willing to push the code out into its own separate .py > file, you can use a module and write your code in a more natural form: > > > # module example.py > var = 999 > > def spam(arg): > return eggs(arg) + var > > def

Re: Namespaces are one honking great idea

2016-07-04 Thread Steven D'Aprano
On Mon, 4 Jul 2016 09:23 pm, jmp wrote: > On 07/01/2016 04:13 PM, Steven D'Aprano wrote: >> But classes are not like the others: they must be instantiated before >> they can be used, and they are more than just a mere namespace grouping >> related entities. Classes support inheritance. Classes sho

Re: Namespaces are one honking great idea

2016-07-04 Thread Lawrence D’Oliveiro
On Tuesday, July 5, 2016 at 10:10:04 AM UTC+12, I wrote: > > On Monday, July 4, 2016 at 11:37:44 PM UTC+12, Chris Angelico wrote: > > > Functions within the namespace can't call other functions within the > > same namespace using unqualified names. This was a stated requirement. > > Doesn’t my @n

Re: Namespaces are one honking great idea

2016-07-04 Thread Lawrence D’Oliveiro
On Monday, July 4, 2016 at 11:37:44 PM UTC+12, Chris Angelico wrote: > Functions within the namespace can't call other functions within the > same namespace using unqualified names. This was a stated requirement. Doesn’t my @namespace decorator provide that? -- https://mail.python.org/mailman/li

Re: Namespaces are one honking great idea

2016-07-04 Thread jmp
On 07/04/2016 01:37 PM, Chris Angelico wrote: On Mon, Jul 4, 2016 at 9:23 PM, jmp wrote: On 07/01/2016 04:13 PM, Steven D'Aprano wrote: But classes are not like the others: they must be instantiated before they can be used, and they are more than just a mere namespace grouping related entitie

Re: Namespaces are one honking great idea

2016-07-04 Thread Chris Angelico
On Mon, Jul 4, 2016 at 9:23 PM, jmp wrote: > On 07/01/2016 04:13 PM, Steven D'Aprano wrote: >> >> But classes are not like the others: they must be instantiated before they >> can be used, and they are more than just a mere namespace grouping related >> entities. Classes support inheritance. Class

Re: Namespaces are one honking great idea

2016-07-04 Thread jmp
On 07/01/2016 04:13 PM, Steven D'Aprano wrote: But classes are not like the others: they must be instantiated before they can be used, and they are more than just a mere namespace grouping related entities. Classes support inheritance. Classes should be used for "is-a" relationships, not "has-a"

Re: Namespaces are one honking great idea

2016-07-03 Thread Ethan Furman
On 07/03/2016 03:02 PM, Kevin Conway wrote: >At some point earlier Ethan Furman declared: It's not a language change. Perhaps. My argument is that anything that introduces a new class-like construct and set of lexical scoping rules is a language change. For example, if this change went into 2.

Re: Namespaces are one honking great idea

2016-07-03 Thread BartC
On 04/07/2016 00:21, Lawrence D’Oliveiro wrote: On Monday, July 4, 2016 at 10:02:59 AM UTC+12, Kevin Conway wrote: If the problem with using classes to satisfy the namespace need is that it's unwieldy to use dot qualified paths then isn't that quite similar to saying namespaces are unwieldy? P

Re: Namespaces are one honking great idea

2016-07-03 Thread Lawrence D’Oliveiro
On Monday, July 4, 2016 at 10:02:59 AM UTC+12, Kevin Conway wrote: > If the problem with using classes to satisfy the namespace need is > that it's unwieldy to use dot qualified paths then isn't that quite similar > to saying namespaces are unwieldy? Python has a simple solution to that: a =

Re: Namespaces are one honking great idea

2016-07-03 Thread Kevin Conway
>> Regardless, all use cases you've listed are already satisfied by use of >> the static and class method decorators. Methods decorated with these do >> not require an instance initialization to use. > And are significantly less easy to use, as the functions MUST refer to each > other by their dot

Re: Namespaces are one honking great idea

2016-07-02 Thread Ethan Furman
On 07/02/2016 08:44 PM, Steven D'Aprano wrote: Try getting this behaviour from within a class: class Food(metaclass=Namespace): # (1) no special decorators required def spam(n): return ' '.join(['spam']*n) # (2) can call functions from inside the namespace breakf

Re: Namespaces are one honking great idea

2016-07-02 Thread Steven D'Aprano
On Sun, 3 Jul 2016 01:34 am, Kevin Conway wrote: > staticmethod isn't technically required to use a method through the class > (or subclasses), it simply provides the appropriate magic to allow it to > be called through instances. > > For example, the following code covers all described use cases

Re: Namespaces are one honking great idea

2016-07-02 Thread Steven D'Aprano
On Sat, 2 Jul 2016 11:50 am, Kevin Conway wrote: > I believe the namespace object you are referring to is exactly a class. Yes, a namespace is exactly like a class, minus inheritance, instantiation, the implied "is-a" relationship, and the whole Java "utility class" anti-pattern. In other words,

Re: Namespaces are one honking great idea

2016-07-02 Thread Ethan Furman
On 07/02/2016 08:34 AM, Kevin Conway wrote: For the proponents of namespace, what is deficient in the above example that necessitates a language change? Adding a new widget is not changing the language. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list

Re: Namespaces are one honking great idea

2016-07-02 Thread Kevin Conway
> staticmethod isn't technically required to use a method through the class (or subclasses), it simply provides the appropriate magic to allow it to be called through instances. For example, the following code covers all described use cases of the proposed namespace. Methods are invoked without cr

Re: Namespaces are one honking great idea

2016-07-01 Thread Random832
On Fri, Jul 1, 2016, at 21:50, Kevin Conway wrote: > I believe the namespace object you are referring to is exactly a > class. IIRC, classes came about as a "module in a module". No, because classes have instances. And conceptually they seem like they *should* have instances. Just using the term "

Re: Namespaces are one honking great idea

2016-07-01 Thread Lawrence D’Oliveiro
On Saturday, July 2, 2016 at 1:50:56 PM UTC+12, Kevin Conway wrote: > Regardless, all use cases you've listed are already satisfied by use of the > static and class method decorators. Except for the need to decorate every such function inside the class. How about: import types def namesp

Re: Namespaces are one honking great idea

2016-07-01 Thread Rustom Mody
On Friday, July 1, 2016 at 8:19:36 PM UTC+5:30, BartC wrote: > On 01/07/2016 15:13, Steven D'Aprano wrote: > > > Sometimes we have a group of related functions and variables that belong > > together, but are not sufficiently unrelated to the rest of the module that > > we want to split them out in

Re: Namespaces are one honking great idea

2016-07-01 Thread Kevin Conway
I believe the namespace object you are referring to is exactly a class. IIRC, classes came about as a "module in a module". Regardless, all use cases you've listed are already satisfied by use of the static and class method decorators. Methods decorated with these do not require an instance initia

Re: Namespaces are one honking great idea

2016-07-01 Thread Steven D'Aprano
On Sat, 2 Jul 2016 05:29 am, Ethan Furman wrote: > On 07/01/2016 10:10 AM, Steven D'Aprano wrote: >> On Sat, 2 Jul 2016 02:00 am, Ethan Furman wrote: > >>> Did you mean for this to go to -Ideas? >> >> Not yet. I wanted some initial feedback to see if anyone else liked the >> idea before taking it

Re: Namespaces are one honking great idea

2016-07-01 Thread Ethan Furman
On 07/01/2016 10:10 AM, Steven D'Aprano wrote: On Sat, 2 Jul 2016 02:00 am, Ethan Furman wrote: Did you mean for this to go to -Ideas? Not yet. I wanted some initial feedback to see if anyone else liked the idea before taking it to Bikeshedding Central :-) Besides, I expect Python-Ideas wil

Re: Namespaces are one honking great idea

2016-07-01 Thread Steven D'Aprano
On Sat, 2 Jul 2016 12:49 am, BartC wrote: > On 01/07/2016 15:13, Steven D'Aprano wrote: > >> Sometimes we have a group of related functions and variables that belong >> together, but are not sufficiently unrelated to the rest of the module >> that we want to split them out into another file. > >

Re: Namespaces are one honking great idea

2016-07-01 Thread Steven D'Aprano
On Sat, 2 Jul 2016 02:00 am, Ethan Furman wrote: > On 07/01/2016 07:13 AM, Steven D'Aprano wrote: > > I like the idea, but I have a couple questions about the design choices. Thanks! > Comments below. [...] >> Despite the "class" statement (a limitation of Python's lack of dedicated >> synt

Re: Namespaces are one honking great idea

2016-07-01 Thread Chris Angelico
On Sat, Jul 2, 2016 at 12:49 AM, BartC wrote: > Why not just extend the capabilities of a class? I actually thought this > would work until I tried it and it didn't: > > class C(): > def fn(): > print ("Hi!") > > C.fn() > > The error message suggests Python knows what's going on. So wh

Re: Namespaces are one honking great idea

2016-07-01 Thread Ethan Furman
On 07/01/2016 07:13 AM, Steven D'Aprano wrote: I like the idea, but I have a couple questions about the design choices. Comments below. The Zen of Python says: Namespaces are one honking great idea -- let's do more of those! Proposal = Add a new "namespace" object to Python

Re: Namespaces are one honking great idea

2016-07-01 Thread BartC
On 01/07/2016 15:13, Steven D'Aprano wrote: Sometimes we have a group of related functions and variables that belong together, but are not sufficiently unrelated to the rest of the module that we want to split them out into another file. Here's a proof of concept. I use a class with a custom

Re: Namespaces are one honking great idea

2016-07-01 Thread Random832
On Fri, Jul 1, 2016, at 10:13, Steven D'Aprano wrote: > The biggest limitation is that I have to abuse the class statement to do > this. In an ideal world, there would be syntactic support and a keyword: > > namespace Example: > x = 0 > y = [] > def test(n): ... > > al

Re: Namespaces in functions vs classes

2011-04-19 Thread Chris Angelico
On Wed, Apr 20, 2011 at 8:00 AM, Rhodri James wrote: > Language abuse: it's not just Python.  A donation of just $5 will keep a > programmer in prepositions for a month.  $50 will supply enough articles to > keep a small company understandable for over a year.  With your generous > help, we can be

Re: Namespaces in functions vs classes

2011-04-19 Thread Rhodri James
On Tue, 19 Apr 2011 17:47:40 +0100, Gerald Britton wrote: Gerald Britton wrote: I now understand the Python does not consider a class definition as a separate namespace as it does for function definitions. That is a helpful understanding. That is not correct. Classes are separate namesp

Re: Namespaces in functions vs classes

2011-04-19 Thread Terry Reedy
On 4/19/2011 10:58 AM, Gerald Britton wrote: serve method unless it is qualified. I now understand the Python does not consider a class definition as a separate namespace as it does for function definitions. Class namespaces are separate namespaces but not in the same way as for functions. C

Re: Namespaces in functions vs classes

2011-04-19 Thread Ian Kelly
On Tue, Apr 19, 2011 at 10:31 AM, Ethan Furman wrote: > Gerald Britton wrote: >> >> I now understand the Python does >> not consider a class definition as a separate namespace as it does for >> function definitions.  That is a helpful understanding. > > That is not correct.  Classes are separate n

Re: Namespaces in functions vs classes

2011-04-19 Thread Gerald Britton
>Gerald Britton wrote: >> I now understand the Python does >> not consider a class definition as a separate namespace as it does for >> function definitions. That is a helpful understanding. >That is not correct. Classes are separate namespaces -- they just >aren't automatically searched. The o

Re: Namespaces in functions vs classes

2011-04-19 Thread Ethan Furman
Gerald Britton wrote: I now understand the Python does not consider a class definition as a separate namespace as it does for function definitions. That is a helpful understanding. That is not correct. Classes are separate namespaces -- they just aren't automatically searched. The only name

Re: Namespaces in functions vs classes

2011-04-19 Thread Gerald Britton
Ethan -- I'm just getting back to this question. If you recall, you asked: [snip] 8< "script with possible name clashes" eggs = 'scrambled eggs' meat = 'steak' class Breakfast(): meat = 'spam' def serve(self): print("Here's

Re: Namespaces in functions vs classes

2011-04-17 Thread Richard Thomas
On Apr 17, 8:56 pm, Chris Rebert wrote: > On Sun, Apr 17, 2011 at 12:30 PM, Gerald Britton > > > > > > > > > > wrote: > > I apologize if this has been answered before or if it is easy to find > > in the docs. (I couldn't find it but might have missed it) > > > I'm trying to understand the differe

Re: Namespaces in functions vs classes

2011-04-17 Thread Ethan Furman
Gerald Britton wrote: For my final attempt, I add the prefix "a." to my use of "foo" class a(): ... foo = 'foo' ... def g(x): ... return a.foo ... The first parameter to any method in a class* is going to be the instance of that class, and is usually named 'self'. So your

Re: Namespaces in functions vs classes

2011-04-17 Thread Ethan Furman
Gerald Britton wrote: However, I would like a deeper understanding of why I cannot use "foo" as an unqualified variable inside the method in the class. If Python allowed such a thing, what problems would that cause? 8< "script with possible

Re: Namespaces in functions vs classes

2011-04-17 Thread Chris Rebert
On Sun, Apr 17, 2011 at 12:30 PM, Gerald Britton wrote: > I apologize if this has been answered before or if it is easy to find > in the docs. (I couldn't find it but might have missed it) > > I'm trying to understand the differences between namespaces in class > definitions vs. function definitio

RE: Namespaces

2011-01-22 Thread Andreas Tawn
> What is namespace? And what is built-in namespace? > -- > http://mail.python.org/mailman/listinfo/python-list http://lmgtfy.com/?q=python+namespace -- http://mail.python.org/mailman/listinfo/python-list

Re: Namespaces

2011-01-21 Thread Michael Sparks
On Jan 21, 10:39 am, sl33k_ wrote: > What is namespace? And what is built-in namespace? tl;dr - Namespaces are sets that contain names. You can think of namespaces as being /like/ boxes. A namespace is therefore an organisational tool, forming a similar purpose to human names & surnames - to iden

Re: Namespaces

2011-01-21 Thread Dave Angel
On 01/-10/-28163 02:59 PM, sl33k_ wrote: What is namespace? And what is built-in namespace? A namespace is a mapping from names to objects. When you write a statement xyz = 42 the system looks up "xyz" in some namespace and associates that "variable" with the object int(42). The key i

Re: Namespaces

2011-01-21 Thread Alex Willmer
On Jan 21, 10:39 am, sl33k_ wrote: > What is namespace? And what is built-in namespace? A namespace is a container for names, like a directory is a container for files. Names are the labels we use to refer to python objects (e.g. int, bool, sys), and each Python object - particularly modules and

Re: namespaces, scoping and variables

2010-08-03 Thread Jean-Michel Pichavant
rantingrick wrote: On Aug 2, 3:12 pm, Chris Hare wrote: Also you should use 4 space indention and never use tabs. This is the accepted way. Then ask yourself why tabs are still in python 3. Nice troll by the way. JM -- http://mail.python.org/mailman/listinfo/python-list

Re: namespaces, scoping and variables

2010-08-02 Thread rantingrick
On Aug 2, 3:12 pm, Chris Hare wrote: > Thanks to everyone for answering my question.  I think its clear now.  I'll > just go the "stuff 'em in a module and import that" route. Chris, first of all i want you to know that this message is not meant to offend but it may offend you -- hopefully your

Re: namespaces, scoping and variables

2010-08-02 Thread Chris Hare
Thanks to everyone for answering my question. I think its clear now. I'll just go the "stuff 'em in a module and import that" route. Chris On Aug 2, 2010, at 3:03 PM, MRAB wrote: > Chris Hare wrote: >> I am having a problem getting around this variable namespace thing. >> Consider these code

Re: namespaces, scoping and variables

2010-08-02 Thread Ethan Furman
Chris Hare wrote: I am having a problem getting around this variable namespace thing. Consider these code bits File a.py from Tkinter import * import a1 def doAgain(): x = a1.Net() x.show("Again!") root = Tk() root.title("test") f = Frame(root,bg="Yellow") l = Button(root,text

Re: namespaces, scoping and variables

2010-08-02 Thread MRAB
Chris Hare wrote: I am having a problem getting around this variable namespace thing. Consider these code bits File a.py from Tkinter import * import a1 def doAgain(): x = a1.Net() x.show("Again!") root = Tk() root.title("test") f = Frame(root,bg="Yellow") l = Button(root,text

Re: namespaces, scoping and variables

2010-08-02 Thread Dave Angel
Chris Hare wrote: I am having a problem getting around this variable namespace thing. Consider these code bits File a.py from Tkinter import * import a1 def doAgain(): x =1.Net() x.show("Again!") root =k() root.title("test") f =rame(root,bg="Yellow") l =utton(root,text="window

Re: namespaces, scoping and variables

2010-08-02 Thread Thomas Jollans
On 08/02/2010 09:33 PM, Chris Hare wrote: > I am having a problem getting around this variable namespace thing. > > Consider these code bits > > File a.py > from Tkinter import * > import a1 > > def doAgain(): > x = a1.Net() > x.show("Again!") > > root = Tk() > root.title("test") >

Re: Namespaces, multiple assignments, and exec()

2008-12-21 Thread John O'Hagan
On Sat, 20 Dec 2008, John O'Hagan wrote: > On Sat, 20 Dec 2008, Terry Reedy wrote: > > John O'Hagan wrote: > > > I have a lot of repetitive assignments to make, within a generator, > > > that use a function outside the generator: > > > > > > var1 = func("var1", args) > > > var2 = func("var2", args)

Re: Namespaces, multiple assignments, and exec()

2008-12-20 Thread Luis M . González
On Dec 19, 11:34 pm, John O'Hagan wrote: > I have a lot of repetitive assignments to make, within a generator, that use a > function outside the generator: > > var1 = func("var1", args) > var2 = func("var2", args) > var3 = func("var3", args) > etc... > > In each case the args are identical, but th

Re: Namespaces, multiple assignments, and exec()

2008-12-20 Thread John O'Hagan
On Sat, 20 Dec 2008, Terry Reedy wrote: > John O'Hagan wrote: > > I have a lot of repetitive assignments to make, within a generator, that > > use a function outside the generator: > > > > var1 = func("var1", args) > > var2 = func("var2", args) > > var3 = func("var3", args) > > etc... > > > > In ea

Re: Namespaces, multiple assignments, and exec()

2008-12-20 Thread John O'Hagan
On Sat, 20 Dec 2008, Steven D'Aprano wrote: > On Sat, 20 Dec 2008 02:53:16 +, MRAB wrote: > > If you're sure you want to use the current namespace then: > > > > for name in namelist: > > vars()[name] = func(name, args) > > Doesn't work inside a function: > >>> def parrot(): > > ..

Re: Namespaces, multiple assignments, and exec()

2008-12-20 Thread John O'Hagan
On Sat, 20 Dec 2008, Arnaud Delobelle wrote: > John O'Hagan writes: > > I have a lot of repetitive assignments to make, within a generator, > > that use a function outside the generator: > > > > var1 = func("var1", args) > > var2 = func("var2", args) > > var3 = func("var3", args) > > etc... > > >

Re: Namespaces, multiple assignments, and exec()

2008-12-20 Thread Arnaud Delobelle
John O'Hagan writes: > I have a lot of repetitive assignments to make, within a generator, > that use a function outside the generator: > > var1 = func("var1", args) > var2 = func("var2", args) > var3 = func("var3", args) > etc... > > In each case the args are identical, but the first argument is

Re: Namespaces, multiple assignments, and exec()

2008-12-19 Thread Steven D'Aprano
On Sat, 20 Dec 2008 02:53:16 +, MRAB wrote: > If you're sure you want to use the current namespace then: > > for name in namelist: > vars()[name] = func(name, args) Doesn't work inside a function: >>> def parrot(): ... for name in ['A', 'B', 'C']: ... vars()[na

Re: Namespaces, multiple assignments, and exec()

2008-12-19 Thread MRAB
Terry Reedy wrote: John O'Hagan wrote: I have a lot of repetitive assignments to make, within a generator, that use a function outside the generator: var1 = func("var1", args) var2 = func("var2", args) var3 = func("var3", args) etc... In each case the args are identical, but the first argumen

Re: Namespaces, multiple assignments, and exec()

2008-12-19 Thread Terry Reedy
John O'Hagan wrote: I have a lot of repetitive assignments to make, within a generator, that use a function outside the generator: var1 = func("var1", args) var2 = func("var2", args) var3 = func("var3", args) etc... In each case the args are identical, but the first argument is a string of the

Re: namespaces and eval

2008-05-20 Thread George Sakkis
On May 16, 5:02 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > Sorry for the repost, didnt' quite finish > > > Suppose I have a function in module X that calls eval e.g, > > > X.py > > ___ > > Def foo(bar): > >         Eval(bar) > > ___ > > > Now eval will b

Re: namespaces and eval

2008-05-20 Thread dave
On May 17, 12:20 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > On May 16, 2:47 pm, "[EMAIL PROTECTED]" > > <[EMAIL PROTECTED]> wrote: > >> On 16 mai, 23:23, [EMAIL PROTECTED] wrote: > > >> > Thanks for the responses. I'm well aware that the function can be > >> >

Re: namespaces and eval

2008-05-17 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: > On May 16, 2:47 pm, "[EMAIL PROTECTED]" > <[EMAIL PROTECTED]> wrote: >> On 16 mai, 23:23, [EMAIL PROTECTED] wrote: >> >> > Thanks for the responses. I'm well aware that the function can be >> > passed in the parameters, passing in the functino as an arg defeats >> > th

Re: namespaces and eval

2008-05-16 Thread dave . g1234
On May 16, 2:47 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On 16 mai, 23:23, [EMAIL PROTECTED] wrote: > > > Thanks for the responses. I'm well aware that the function can be > > passed in the parameters, passing in the functino as an arg defeats > > the purpose of what I'm going after. >

Re: namespaces and eval

2008-05-16 Thread [EMAIL PROTECTED]
On 16 mai, 23:23, [EMAIL PROTECTED] wrote: > Thanks for the responses. I'm well aware that the function can be > passed in the parameters, passing in the functino as an arg defeats > the purpose of what I'm going after. Why so ? > @ Arnaud - Nice. I'm not sure what the performance of mine vs. yo

Re: namespaces and eval

2008-05-16 Thread dave . g1234
Thanks for the responses. I'm well aware that the function can be passed in the parameters, passing in the functino as an arg defeats the purpose of what I'm going after. @ Arnaud - Nice. I'm not sure what the performance of mine vs. yours, but a perfunctory glance looks like we're doing the clos

Re: namespaces and eval

2008-05-16 Thread [EMAIL PROTECTED]
On 16 mai, 20:44, [EMAIL PROTECTED] wrote: > Suppose I have a function in module X that calls eval e.g, > > X.py > ___ > Def foo(bar): > Eval(bar) > ___ > > Now eval will be called using the default eval(bar,globals(),locals()) > and globals will pull in anything in module X. > > No

Re: namespaces and eval

2008-05-16 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: > Sorry for the repost, didnt' quite finish > > Suppose I have a function in module X that calls eval e.g, > > X.py > ___ > Def foo(bar): > Eval(bar) > ___ > > Now eval will be called using the default eval(bar,globals(),locals()) > and globals will pull i

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-25 Thread Aahz
In article <[EMAIL PROTECTED]>, Alex Martelli <[EMAIL PROTECTED]> wrote: >Aahz <[EMAIL PROTECTED]> wrote: >>Alex: >>> >>>But don't put such black magic in production. The completely different >>>way is: just don't. >> >> Could you expand on that? After all, that's exactly what we do to >> implem

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Alex Martelli
Martin Drautzburg <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > > Yes, there is: use an ORM to do the SQL generation for you. Check out > > SQLAlchemy, it will buy you much more than what you asked for. > > Might look, though in general I don't like OR mappers much. Having SQL > generate

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Alex Martelli
Aahz <[EMAIL PROTECTED]> wrote: > >But don't put such black magic in production. The completely different > >way is: just don't. > > Could you expand on that? After all, that's exactly what we do to > implement a super() that works with classic classes -- and it's certainly > production code.

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Aahz
In article <[EMAIL PROTECTED]>, Alex Martelli <[EMAIL PROTECTED]> wrote: >Martin Drautzburg <[EMAIL PROTECTED]> wrote: >> >> The problem is the first part: how can I lookup the callers module and >> the classobjs defined in there? Or finding any constant strings in the >> caller's module would also

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-23 Thread Martin Drautzburg
Peter Otten wrote: def SQL(sql): > ...     print sql > ... a = SQL("module") > module # that one was obvious class A: > ...     b = SQL("class") > ...     def method(self, c=SQL("default arg")): > ...             d = SQL("method") > ... You are my hero. Indeed very cool! -- http:/

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Martin Drautzburg
George Sakkis wrote: > Yes, there is: use an ORM to do the SQL generation for you. Check out > SQLAlchemy, it will buy you much more than what you asked for. Might look, though in general I don't like OR mappers much. Having SQL generated feels as strange as having python code generated. Too much

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Peter Otten
Martin Drautzburg wrote: > > def SQL(sql, checked=set()): > > if sql in checked: > > return True > > if not valid_sql(sql): raise ValueError > > checked.add(sql) > > return sql > > No this does not do the trick. I will not be able to validate an sql > statement bofore I ru

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Alex Martelli
Martin Drautzburg <[EMAIL PROTECTED]> wrote: ... > The problem is the first part: how can I lookup the callers module and > the classobjs defined in there? Or finding any constant strings in the > caller's module would also be just fine. Or is there a completely > different way to do such a thin

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread George Sakkis
On Apr 21, 4:16 pm, Martin Drautzburg <[EMAIL PROTECTED]> wrote: > I would like to validate sql strings, which are spread all over the > code, i.e. I run ("prepare") them against a database to see if it happy > with the statements. Spelling errors in sql have been a major pain for > me. > > The sta

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Scott David Daniels
Martin Drautzburg wrote: > I would like to validate sql strings, which are spread all over the > code, The statements will not be assembled from smaller pieces, > but they will not neccessarily be defined at module level. I could > live with class level, > parse the source file, but I am

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Martin Drautzburg
Peter Otten wrote: > Martin Drautzburg wrote: > >> I would like to validate sql strings, which are spread all over the >> code, i.e. I run ("prepare") them against a database to see if it >> happy with the statements. Spelling errors in sql have been a major >> pain for me. > > def validateSQL(

Re: Namespaces/introspection: collecting sql strings for validation

2007-04-22 Thread Peter Otten
Martin Drautzburg wrote: > I would like to validate sql strings, which are spread all over the > code, i.e. I run ("prepare") them against a database to see if it happy > with the statements. Spelling errors in sql have been a major pain for > me. > > The statements will not be assembled from sma

Re: namespaces

2005-08-10 Thread Paolino
Bengt Richter wrote: > Another thought/bf would be a way to extend the attribute namespace of an > arbitrary object > by chaining the attribute name spaces of a sequence of objects (this would be > a language mod) > e.g., (sort of a dynamic instance attribute mixin) > > obj ..= a, b, c #

Re: namespaces

2005-08-10 Thread Paolino
Scott David Daniels wrote: > Well, an entry in the dictionary "sys.modules" is what is returned by > imports, so you could either pre-replace or post-replace a module by > an object which uses the descriptor technique to get to some (but not > necessarily all) of the attributes. Think of this tec

Re: namespaces

2005-08-09 Thread Simon Burton
I've been needing a module level __getattr__ for some c library wrapping. This has solved the problem: # mymod.py: import sys from new import module class ModuleProxy(module): def __init__( self, name, master ): module.__init__( self, name ) self._master = master self.__dict__["__all

Re: namespaces

2005-08-09 Thread Aahz
In article <[EMAIL PROTECTED]>, Paolino <[EMAIL PROTECTED]> wrote: > >Why descriptor mechanism doesn't apply to modules? The real answer: Because Guido doesn't want it to -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ The way to build large Python applications is

Re: namespaces

2005-08-09 Thread Bengt Richter
On Tue, 09 Aug 2005 08:35:38 -0700, Scott David Daniels <[EMAIL PROTECTED]> wrote: >Paolino wrote: >> Peter Otten wrote: >>> Paolino wrote: Why descriptor mechanism doesn't apply to modules? >>> Because modules are instances of the module class and the descriptor >>> has to be defined in th

  1   2   >