Python Language Lesson: object
Objects hold together variables and the functions that manipulate them.In many cases, functions and variables are so closely related to each
other that they would be meaningless if they were handled separately.
Objects are especially useful in large, complicated applications which
would be practically incomprehensible if they were not divided into
smaller units.
Python does much of this work for you, so you can code happily
with Python’s ready-made objects. Developing large and complex
applications in an object-oriented manner is out of the scope of this
book. There is a lot of information about object-oriented programming
in other books and on the web. You may be surprised to see that
example applications which are used to teach object orientation are
not complex at all with Python and they do not require you to derive
objects of your own.
For our purposes, it is enough to know that some functions create
objects. In Example 11, an Ao lock object is assigned to the variable
app lock.
app lock = e32.Ao lock()
The object itself contains variables and functions that can be
accessed with the dot notation, for example:
app lock.wait()
calls the object’s wait() function. Likewise:
appuifw.app.title = u"Hello World"
assigns a value to the title variable of the app object in the appuifw
module. In practice, you can treat objects as if they are modules inside
modules, as the dot notation suggests.
In this chapter, you can find many examples of object usage. You
have already seen the app object which handles the standard user
interface and the Ao lock object which is used to wait for user actions.
In practice, everything in Python is an object, including strings, lists and
tuples, as well as more specific constructs such as the Inbox object,
which is used to access SMS messages. Objects are so ubiquitous in
Python that you use them all the time without even noticing it.
Nice... Ride on
ReplyDelete