Re: Generate a new object each time a name is imported

2009-08-06 Thread Michele Simionato
On Aug 2, 1:18 pm, Paul Rubin wrote: > Peter Otten <__pete...@web.de> writes: > > >>> import sys > > >>> sys.modules["yadda"] = A() > > OMG wow.  I bow to you.  But I'm not sure whether that's bowing in > awe or in terror. I had to play this kind of tricks on our

Re: Generate a new object each time a name is imported

2009-08-03 Thread Steven D'Aprano
On Mon, 03 Aug 2009 16:38:43 +0200, Jean-Michel Pichavant wrote: > So what's the purpose of making > >>from Module import factory as a >>from Module import factory as b > > return 2 different objects ? If I had to write this code I would expect > 'a is b' to return 'True'. > > This is no "don'

Re: Generate a new object each time a name is imported

2009-08-03 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: I would like to generate a new object each time I import a name from a module, rather than getting the same object each time. For example, currently I might do something like this: # Module count = 0 def factory(): # Generate a unique object each time this is called

Re: Generate a new object each time a name is imported

2009-08-02 Thread alex23
On Aug 3, 4:07 am, Terry Reedy wrote: > Peter Otten wrote: > > Steven D'Aprano wrote: [...] Fantastic question, answer & explanation, guys. Well done. -- http://mail.python.org/mailman/listinfo/python-list

Re: Generate a new object each time a name is imported

2009-08-02 Thread Terry Reedy
Peter Otten wrote: Steven D'Aprano wrote: I'm looking for a way to hide the generation of objects from the caller, so I could do something like this: from Module import factory() as a # a == "Object #1" from Module import factory() as b # b == "Object #2" except of course that syntax is il

Re: Generate a new object each time a name is imported

2009-08-02 Thread Peter Otten
wrote: KNode cannot parse your From-string correctly. Strange. > Peter Otten <__pete...@web.de> writes: >> >>> import sys >> >>> sys.modules["yadda"] = A() > > OMG wow. I bow to you. But I'm not sure whether that's bowing in > awe or in terror. I don't know who invented it, but it's an o

Re: Generate a new object each time a name is imported

2009-08-02 Thread Paul Rubin
Peter Otten <__pete...@web.de> writes: > >>> import sys > >>> sys.modules["yadda"] = A() OMG wow. I bow to you. But I'm not sure whether that's bowing in awe or in terror. -- http://mail.python.org/mailman/listinfo/python-list

Re: Generate a new object each time a name is imported

2009-08-02 Thread Steven D'Aprano
On Sun, 02 Aug 2009 12:33:03 +0200, Peter Otten wrote: > How about [snip] import sys sys.modules["yadda"] = A() Perfect! That's exactly the sort of thing I'm looking for. Thanks for everyone who answered. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Generate a new object each time a name is imported

2009-08-02 Thread Peter Otten
Steven D'Aprano wrote: > I would like to generate a new object each time I import a name from a > module, rather than getting the same object each time. For example, > currently I might do something like this: > > # Module > count = 0 > def factory(): > # Generate a unique object each time th

Re: Generate a new object each time a name is imported

2009-08-02 Thread Hrvoje Niksic
Steven D'Aprano writes: > I'm looking for a way to hide the generation of objects from the caller, > so I could do something like this: > > from Module import factory() as a # a == "Object #1" > from Module import factory() as b # b == "Object #2" > > except of course that syntax is illegal.

Re: Generate a new object each time a name is imported

2009-08-02 Thread Jonathan Gardner
On Aug 2, 12:35 am, Steven D'Aprano wrote: > > I'm looking for a way to hide the generation of objects from the caller, > so I could do something like this: > > from Module import factory() as a  # a == "Object #1" > from Module import factory() as b  # b == "Object #2" > Explicit is better than