How to start a Python project part2: Skeleton

You should begin almost every application the same way: by creating a “skeleton” for the application consisting of functions and classes with doc strings but no implementation. 

To serve as an example application, we will use a script recently created by a tutoring client during one of our sessions. The goal of the script is to create a csv file containing the top grossing movies of last year (from IMDB) and the keywords on IMDB associated with them. This was a simple enough project that it could be completed in one session, but meaty enough to require some thought.

First, create a main file to serve as the entry point to your application. We will call it imdb.py. Next, copy-and-paste the following code into your editor (and change the docstring as appropriate):

"""Script to gather IMDB keywords from 2013's top grossing movies."""
import sys

def main():
    """Main entry point for the script."""
    pass

if __name__ == '__main__':
    sys.exit(main())

While it may not look like much, this is a fully functional Python program. You can run it directly and get back the proper return code (0, though to be fair, running an empty file will also return the proper code). Next we will create stubs for the functions and/or classes that we think are needed.:

"""Script to gather IMDB keywords from 2013's top grossing movies."""
import sys

URL = "http://www.imdb.com/search/title?at=0&sort=boxoffice_gross_us,desc&start=1&year=2013,2013"

def main():
    """Main entry point for the script."""
    pass

def get_top_grossing_movie_links(url):
    """Return a list of tuples containing the top grossing movies of 2013 and link to their IMDB
    page."""
    pass

def get_keywords_for_movie(url):
    """Return a list of keywords associated with *movie*."""
    pass

if __name__ == '__main__':
    sys.exit(main())

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.