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

Thanks!
This commit is contained in:
Christian Clauss 2020-04-07 23:46:03 +02:00 committed by GitHub
parent e8ce1c4caf
commit cd646f9971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 13 deletions

View File

@ -1,4 +1,6 @@
#!/bin/python #!/bin/python
from __future__ import print_function
import urllib, urllib2 import urllib, urllib2
import json import json
@ -14,7 +16,7 @@ class HyriseConnection(object):
def __parseResponse(self, response): def __parseResponse(self, response):
result = json.loads(response) result = json.loads(response)
if 'error' in result: if 'error' in result:
print 'An error occurred: %s' % result['error'][0] print('An error occurred: %s' % result['error'][0])
return None return None
if 'performanceData' in result: if 'performanceData' in result:
@ -47,10 +49,10 @@ class HyriseConnection(object):
rsp = urllib2.urlopen(req) rsp = urllib2.urlopen(req)
response = rsp.read(); response = rsp.read();
return self.__parseResponse(response) return self.__parseResponse(response)
except TypeError, e: except TypeError as e:
print "An error occurred" print("An error occurred")
return None return None
except Exception, e: except Exception as e:
return self.__parseResponse(e.read()) return self.__parseResponse(e.read())
def __aggregatePerfArray(self, perfArray): def __aggregatePerfArray(self, perfArray):
@ -160,8 +162,8 @@ if __name__ == '__main__':
# if 'prepare' in query: hyrise.executeSQL(query['prepare']) # if 'prepare' in query: hyrise.executeSQL(query['prepare'])
if 'sql' in query: print 'SQL: ', hyrise.executeSQL(query['sql'], times) if 'sql' in query: print('SQL: ', hyrise.executeSQL(query['sql'], times))
if 'execute' in query: print 'Prepared: ', hyrise.executeSQL(query['execute'], times) if 'execute' in query: print('Prepared: ', hyrise.executeSQL(query['execute'], times))
# if 'json' in query: print 'JSON: ', hyrise.executeJSON(query['json'], times) # if 'json' in query: print('JSON: ', hyrise.executeJSON(query['json'], times))

View File

@ -1,4 +1,4 @@
from __future__ import print_function
import math import math
@ -21,7 +21,7 @@ with open("sql_keywords.txt", 'r') as fh:
if len_diff % 4 != 0: num_tabs += 1 if len_diff % 4 != 0: num_tabs += 1
tabs = ''.join(['\t' for _ in range(num_tabs)]) tabs = ''.join(['\t' for _ in range(num_tabs)])
print "%s%sTOKEN(%s)" % (keyword, tabs, keyword) print("%s%sTOKEN(%s)" % (keyword, tabs, keyword))
# #
################# #################
@ -32,15 +32,15 @@ with open("sql_keywords.txt", 'r') as fh:
line = "%token" line = "%token"
max_len = 60 max_len = 60
print "/* SQL Keywords */" print("/* SQL Keywords */")
for keyword in keywords: for keyword in keywords:
if len(line + " " + keyword) > max_len: if len(line + " " + keyword) > max_len:
print line print(line)
line = "%token " + keyword line = "%token " + keyword
else: else:
line = line + " " + keyword line = line + " " + keyword
print line print(line)
# #
################# #################