Linux Today: Linux News On Internet Time.

Intro to Python Introspection and Dynamic Programming

Jul 01, 2009, 03:02 (0 Talkback[s])
(Other stories by Phillip Watts)

"In this example we have defined a parent class, Device, which has attributes, and some child classes which contain their particular attributes. We have created a list of instances of the devices. In the "for loop" we do something only if the device has the attribute getEths. Therefore we are using internal information about the program, i.e. its classes, to control the program's behaviour.

"By the way, this is sometimes referred to as "duck typing". If it looks like a duck it must be a duck, therefore you can treat it as a duck.

"Before proceeding, we should note that the Python language has much similarity to a Python program, in that, everything in the language is an object. For now we will limit the discussion to classes and instances of classes. Just remember that Python has many built in classes, there are hundreds in the "standard" libraries,and many thousands which can be downloaded and all of the classes themselves share some common properties."

Complete Story

Related Stories: