Use print() function in both Python 2 and Python 3

This commit is contained in:
cclauss
2019-01-13 17:16:37 +01:00
parent 77bc40fe95
commit 8fca11b85c
56 changed files with 300 additions and 244 deletions

View File

@@ -1,3 +1,4 @@
from __future__ import print_function
import json
import sys
import traceback
@@ -14,12 +15,12 @@ else:
def display(message):
print '{} - {}'.format(date_string(message['time']), message['event_type'])
print('{} - {}'.format(date_string(message['time']), message['event_type']))
if message.get('event'):
event = json.loads(message['event'])
for k in sorted(event):
print '\t{}: {}'.format(k, event[k])
print
print('\t{}: {}'.format(k, event[k]))
print()
while 1:
line = sys.stdin.readline()

View File

@@ -1,3 +1,4 @@
from __future__ import print_function
import argparse
import csv
import json
@@ -104,7 +105,7 @@ def _get_course_data_summary(auth_token, months_restriction, xblock_type_set, ap
# print to update the screen for status
sys.stdout.write('.')
sys.stdout.flush()
print 'Processed %d courses' % total_courses
print('Processed %d courses' % total_courses)
return course_summary_data
@@ -159,15 +160,15 @@ def _get_block_types_from_json_file(xblock_json_file):
set: A set of strings for all the types that are available in the configuration file
"""
if not os.path.isfile(xblock_json_file):
print 'xBlock configuration file does not exist: %s' % xblock_json_file
print('xBlock configuration file does not exist: %s' % xblock_json_file)
sys.exit(2)
with open(xblock_json_file, 'r') as json_file:
type_set = set()
try:
json_data = json.loads(json_file.read())
except ValueError as e:
print 'xBlock configuration file does not match the expected layout and is ' \
'missing "data" list: %s' % xblock_json_file
print('xBlock configuration file does not match the expected layout and is ' \
'missing "data" list: %s' % xblock_json_file)
sys.exit(text_type(e))
if 'data' in json_data:
xblock_type_list = json_data['data']
@@ -175,8 +176,8 @@ def _get_block_types_from_json_file(xblock_json_file):
type_set.add(xblock['name'])
return type_set
else:
print 'xBlock configuration file does not match the expected layout and is ' \
'missing "data" list: %s' % xblock_json_file
print('xBlock configuration file does not match the expected layout and is ' \
'missing "data" list: %s' % xblock_json_file)
sys.exit(2)
@@ -374,7 +375,7 @@ if __name__ == "__main__":
# Get User access token
token = get_access_token(username, password, oauth2_client_id, api_root)
if token is None:
print 'Failed to retrieve user token for user: %s ' % username
print('Failed to retrieve user token for user: %s ' % username)
sys.exit(2)
# Collect course data and write CSV reports
@@ -384,4 +385,4 @@ if __name__ == "__main__":
if len(course_data) > 0:
write_block_summary_report(course_data)
write_course_block_detail_report(course_data)
print 'Start time: %s Total run time: %s' % (str(start_time), str(datetime.now() - start_time))
print('Start time: %s Total run time: %s' % (str(start_time), str(datetime.now() - start_time)))