O'Reilly logo

Modern Python Cookbook by Steven F. Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting ready

In the Designing scripts for composition recipe, we looked at an application that produced a YAML file with the raw output of a simulation in it. In this recipe, we'll look at an application that consumes that raw data and produces some statistical summaries. We'll call this application overview_stats.py.

Following the design pattern of separating the input, output, and processing, we'll have an application main() that looks something like this:

    def main(): 
        options = get_options(sys.argv[1:]) 
        if options.output is not None: 
            report_path = Path(options.output) 
            with report_path.open('w') as result_file: 
                process_all_files(result_file, options.file) 
        else: 
            process_all_files(sys.stdout, options.file) 

This function will get the options ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required