This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| base_query = Casualty.safe_objects.all() | |
| def build_chart(base_query, field_name, order_by): | |
| ''' | |
| This is a function to make building our charts a little DRYer. Beats the pants off of lambdas. | |
| ''' | |
| return base_query.values(field_name).annotate(Count(field_name)).order_by(order_by) | |
| extra_context_dict = { | |
| 'theater_chart':build_chart(base_query, 'theater__name', '-theater__name__count'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import csv | |
| source_file = open('/path/to/Testfile.txt','rb') | |
| # Use the DictReader class to read in your data. This class allows you to access | |
| # field names by name. It assumes the first line in the file contains the field names | |
| for line in csv.DictReader(source_file, delimiter='\t'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| A simple script showing how to read data from a specified | |
| file, do some basic processing, and then print out processed | |
| lines to the shell. The input file is hard-coded in the text. | |
| USAGE from command line | |
| python simple_file_processing.py |
NewerOlder