Mercurial > hg > config
annotate python/example/aspects.py @ 842:03f9657514e9
while we might not want Octave *that* much, we will never want OCAML
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 09 Jul 2017 15:01:16 -0700 |
parents | 0fffb3560641 |
children |
rev | line source |
---|---|
124
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
1 class MakePythonLikeJavascript(object): |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
2 def __getattr__(self, name): |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
3 return undefined |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
4 |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
5 class undefined(MakePythonLikeJavascript): |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
6 def __nonzero__(self): |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
7 return False |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
8 def __str__(self): |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
9 return 'undefined' |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
10 __repr__ = __str__ |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
11 undefined = undefined() # singleton |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
12 |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
13 if __name__ == '__main__': |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
14 foo = MakePythonLikeJavascript() |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
15 foo.bar = 5 |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
16 print foo.bar |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
17 print foo.fleem |
2f0baf81372f
added illustration of doing aspects in python
Jeff Hammel <jhammel@mozilla.com>
parents:
diff
changeset
|
18 print foo.fleem.flarg |