annotate python/example/classes.py @ 807:26786fae0703

this relies on a requirement that is not part of my (2.7.12) stdlib; i almost deleted it. instead, i will keep for fun and note the requirement for further research
author Jeff Hammel <k0scist@gmail.com>
date Fri, 28 Oct 2016 17:09:04 -0700
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)))