Presentation given to the Orlando Python Meetup.
"Introspection is a feature of some programming languages that allows a running program to obtain information about its own implementation."
- Free On-Line Dictionary of Computing
Introspection is often the entry point to framework development and other advanced programming concepts.
7. Tell me about yourself?
>>> isinstance.__doc__
"isinstance(object, class-or-type-or-tuple) -> boolnnReturn
whether an object is an instance of a class or of a subclass
thereof.nWith a type as second argument, return whether that
is the object's type.nThe form using a tuple, isinstance(x, (A, B,
...)), is a shortcut fornisinstance(x, A) or isinstance(x, B) or ...
(etc.)."
>>>
8. What class do you belong to?
>>> isinstance.__class__
<type 'builtin_function_or_method'>
>>>
9. Let’s Make a Person
>>> class Person(object):
... """represents a human"""
... def talk(self):
... print "Hello, I'm a person!"
...
>>> p = Person()
>>> p.talk()
Hello, I'm a person!
>>> dir(p)
['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__',
'__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'talk']
>>> p.__doc__
'represents a human'
>>>
>>> p.__module__
'__main__'
>>>
10. Do you have Something I’m
Looking For?
>>> hasattr(p, 'talk')
True
>>> hasattr(p, 'grunt')
False
>>>
13. Program Structure
• Import all modules in CWD that start with “test”
• Import all class in modules that start with “Test”
• Create instances of classes
• Call all member functions that start with “test”
15. Upcoming Events!
Orlando Data Science
January 26
Apache NiFi: Joe Witt of Hortonworks
Meetup.com/orlandodata
Orlando Golang Meetup
February 11
Testing in Go
Meetup.com/orlandogolang
16. Thank You!
Scott Crespo
SSE, The Topps Company
• scott@orlandods.com
• Linkedin.com/in/scottcrespo
• Github.com/scottcrespo
• ODev Slack: scottcrespo
• Code Examples: github.com/scottcrespo/introspection_demo