-
-
Save vrutkovs/fba4f1ee5dc0c7d77341 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrackerWrapper: | |
class __TrackerWrapper: | |
def __init__(self): | |
self.tracker = Tracker.SparqlConnection.get(None) | |
def __str__(self): | |
return repr(self) | |
instance = None | |
def __init__(self): | |
if not TrackerWrapper.instance: | |
TrackerWrapper.instance = TrackerWrapper.__TrackerWrapper() | |
def __getattr__(self, name): | |
return getattr(self.instance, name) # not actually sure if this is necessary, it's code left over from example | |
# compare to example at http://python-3-patterns-idioms-test.readthedocs.org/en/latest/Singleton.html | |
In [58]: a = TrackerWrapper() | |
In [59]: b = TrackerWrapper() | |
In [60]: c = TrackerWrapper() | |
In [61]: a | |
Out[61]: <__main__.TrackerWrapper at 0x7fdcac023dd8> | |
In [62]: b | |
Out[62]: <__main__.TrackerWrapper at 0x7fdcac023da0> | |
In [63]: c | |
Out[63]: <__main__.TrackerWrapper at 0x7fdcac023d68> | |
In [65]: print(a) | |
<__main__.TrackerWrapper object at 0x7fdcac023dd8> | |
In [66]: print(b) | |
<__main__.TrackerWrapper object at 0x7fdcac023da0> | |
In [67]: print(c) | |
<__main__.TrackerWrapper object at 0x7fdcac023d68> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment