annotate python/example/classes.py @ 767:35f8751c0930

it is very annoying to have ones overrides overridden; see also http://stackoverflow.com/questions/25381304/why-type-cd-on-mac-os-states-that-cd-is-a-function
author Jeff Hammel <k0scist@gmail.com>
date Thu, 28 Jan 2016 14:02:17 -0800
parents 870af8d51552
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
626
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3 """
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 illustrate how classes work
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 """
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7 class A:
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 pass
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9
627
870af8d51552 STUB: python/example/classes.py
Jeff Hammel <k0scist@gmail.com>
parents: 626
diff changeset
10 tests = ["issubclass(A(), A)",
870af8d51552 STUB: python/example/classes.py
Jeff Hammel <k0scist@gmail.com>
parents: 626
diff changeset
11 "issubclass(A, A)"]
626
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
13 if __name__ == '__main__':
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 for test in tests:
89a72399286b adding file demonstrating classes
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15 print ("? {}".format(test))
627
870af8d51552 STUB: python/example/classes.py
Jeff Hammel <k0scist@gmail.com>
parents: 626
diff changeset
16 try:
870af8d51552 STUB: python/example/classes.py
Jeff Hammel <k0scist@gmail.com>
parents: 626
diff changeset
17 print (eval(test))
870af8d51552 STUB: python/example/classes.py
Jeff Hammel <k0scist@gmail.com>
parents: 626
diff changeset
18 except Exception as e:
870af8d51552 STUB: python/example/classes.py
Jeff Hammel <k0scist@gmail.com>
parents: 626
diff changeset
19 print ('{}'.format(repr(e)))