Hardware Reference
In-Depth Information
Testing As You Go
If you wrote a huge program and tried to run it, chances are it wouldn't work the irst time.
You'd then have to go through all of it trying to ind where the problem was. Instead, it is
better to test as you go, checking each component before moving on to the next. Python
provides a good means to do this. Toward the end of the ile are the following lines:
if __name__ == '__main__':
test_chicken()
his code calls the test_chicken() function if the ile is being run by itself, but doesn't
call the function if it is imported as a module. As such, it's a good way of writing code that
will test the behaviour of a module. As you learn more about programming, you will under-
stand the importance of testing and which tools and techniques can help.
Surrounding or starting a word with __ in Python (and some other languages) indicates a
special meaning. As such, it's better not to start and end your own variables and functions this
way unless you really know what you're doing!
Connecting to Twitter
he python-twitter module makes it very easy to read from Twitter. Unfortunately the
module isn't prepackaged for Debian Linux. Luckily it's not too diicult to build it from source
and doing so will give you good experience that will come in handy if you need to install another
module in the future. You'll also see what it's like to use someone else's module, which will be
an advantage if you write modules that you want other people to reuse. You'll discover that it is
just as important to write good documentation as it is to write good code.
Building and Installing Python Modules
he module's home page http://code.google.com/p/python-twitter contains a
summary of how to build the module. If you've never built a module before, you're better of
following the more detailed steps in this chapter.
he website lists and links to dependencies; these are other modules that must be built irst.
python-twitter requires simplejson , httplib2 and python-oauth2 to be installed.
Step-by-step installation instructions are provided in this chapter.
 
Search WWH ::




Custom Search