Small Troll on notation of variables over time

Hendrik van Rooyen mail at microcorp.co.za
Mon Aug 21 08:41:54 EDT 2006


"Jeremy Sanders" <jeremy+complangpython at jeremysanders.net> wrote:

| Hendrik van Rooyen wrote:
| 
| > What do you guys think?
| 
| You could get something similar using an object, such as
| 
| class Hist(object):
| 
|     def __init__(self):
|         self.vals = [None]
| 
|     def __call__(self, index=-1):
|         return self.vals[index]
| 
|     def set(self, val):
|         self.vals.append(val)
| 
| a = Hist()
| 
| a.set(5)
| print a()
| 
| a.set('hi there')
| print a()
| print a(-2)
| 
| Which prints
| 5
| hi there
| 5

 - Sneaky!  - I like this....

- Hendrik




More information about the Python-list mailing list