Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4570
| References | <d8d1d20e-2edd-49e5-917c-f338ef35006f@l18g2000yql.googlegroups.com> <vTWvp.23964$vC5.14171@newsfe01.iad> <b2d938e7-7df3-461b-a952-47a81000a335@26g2000yqa.googlegroups.com> <5299438d-611f-4a63-b1d8-4abe039ad5d4@k3g2000prl.googlegroups.com> |
|---|---|
| Date | 2011-05-04 06:55 +1100 |
| Subject | Re: Why do directly imported variables behave differently than those attached to imported module? |
| From | Daniel Kluev <dan.kluev@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1119.1304452508.9059.python-list@python.org> (permalink) |
On Wed, May 4, 2011 at 6:23 AM, Dun Peal <dunpealer@gmail.com> wrote:
> P.S. now I have to ask: is there a symbolic reference in Python, i.e.
> a name foo that points to "whatever bar.baz is pointing at"?
Well, you could easily simulate that with proxy object,
class SymbolicReference(object):
def __init__(self, ns, name):
self.__ns = ns
self.__name = name
def __get(self):
return self.__ns[self.__name]
def __getattribute__(self, attr):
try:
return object.__getattribute__(self, attr)
except:
return self.__get().__getattribute__(attr)
def __repr__(self):
return self.__get().__repr__()
def __str__(self):
return self.__get().__str__()
>>> a = 1
>>> b = SymbolicReference(globals(), 'a')
>>> b
1
>>> a = 10
>>> b
10
--
With best regards,
Daniel Kluev
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Why do directly imported variables behave differently than those attached to imported module? Dun Peal <dunpealer@gmail.com> - 2011-05-03 09:31 -0700
Re: Why do directly imported variables behave differently than those attached to imported module? Chris Rebert <clp2@rebertia.com> - 2011-05-03 09:57 -0700
Re: Why do directly imported variables behave differently than those attached to imported module? Daniel Kluev <dan.kluev@gmail.com> - 2011-05-04 03:57 +1100
Re: Why do directly imported variables behave differently than those attached to imported module? Mel <mwilson@the-wire.com> - 2011-05-03 13:00 -0400
Re: Why do directly imported variables behave differently than those attached to imported module? Terry Reedy <tjreedy@udel.edu> - 2011-05-03 13:13 -0400
Re: Why do directly imported variables behave differently than those attached to imported module? harrismh777 <harrismh777@charter.net> - 2011-05-03 12:24 -0500
Re: Why do directly imported variables behave differently than those attached to imported module? Dun Peal <dunpealer@gmail.com> - 2011-05-03 11:51 -0700
Re: Why do directly imported variables behave differently than those attached to imported module? Dun Peal <dunpealer@gmail.com> - 2011-05-03 12:23 -0700
Re: Why do directly imported variables behave differently than those attached to imported module? Daniel Kluev <dan.kluev@gmail.com> - 2011-05-04 06:55 +1100
Re: Why do directly imported variables behave differently than those attached to imported module? Chris Angelico <rosuav@gmail.com> - 2011-05-04 07:47 +1000
Re: Why do directly imported variables behave differently than those attached to imported module? Duncan Booth <duncan.booth@invalid.invalid> - 2011-05-04 08:44 +0000
Re: Why do directly imported variables behave differently than those attached to imported module? Chris Rebert <clp2@rebertia.com> - 2011-05-03 15:11 -0700
csiph-web