Skip to content

Commit

Permalink
Use print() function in both Python 2 and Python 3
Browse files Browse the repository at this point in the history
Legacy __print__ statements are syntax errors in Python 3 but __print()__ function works as expected in both Python 2 and Python 3.
  • Loading branch information
cclauss committed Jan 16, 2020
1 parent 76fd9b5 commit 0a12441
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
9 changes: 5 additions & 4 deletions examples/models/h2o_example/H2OModel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import numpy as np
import h2o
from h2o.frame import H2OFrame
Expand All @@ -19,13 +20,13 @@ class H2OModel():

def __init__(self):

print 'Starting Java virtual machine'
print('Starting Java virtual machine')
h2o.init(nthreads = -1, max_mem_size = 8)
print 'Machine started!'
print('Machine started!')

print 'Loading model from %s...' % MODEL_PATH
print('Loading model from %s...' % MODEL_PATH)
self.model = h2o.load_model(MODEL_PATH)
print 'Model Loaded'
print('Model Loaded')

def predict(self,X,feature_names):
return _from_frame(self.model.predict(_to_frame(X,feature_names)))
Expand Down
3 changes: 2 additions & 1 deletion examples/models/sigmoid_predictor/SigmoidPredictor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import numpy as np
from sklearn.neural_network import MLPClassifier

Expand All @@ -15,6 +16,6 @@ def __init__(self):

self.ffnn = MLPClassifier()
self.ffnn.fit(X,y)
print "Class", self, "variables", dir(self)
print("Class", self, "variables", dir(self))
def predict(self,X,features_names):
return self.ffnn.predict_proba(X)
5 changes: 3 additions & 2 deletions kafka/tests/src/read_predictions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os
import sys, getopt, argparse
import logging
Expand All @@ -24,7 +25,7 @@
consumer.assign([partition])
consumer.seek(partition, 0)
for msg in consumer:
print msg
print(msg)
message = ppb.PredictionRequestResponseDef()
message.ParseFromString(msg.value)
print message
print(message)
27 changes: 14 additions & 13 deletions util/loadtester/scripts/predict_rest_locust.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from locust.stats import RequestStats
from locust import HttpLocust, TaskSet, task, events
import os
Expand Down Expand Up @@ -43,9 +44,9 @@ def parse_arguments():
args, unknown = parser.parse_known_args()
#args = parser.parse_args()
opts = vars(args)
print args
print(args)
if args.slave:
print "Sleeping 10 secs hack"
print("Sleeping 10 secs hack")
time.sleep(10)
connect_to_master(args.master_host,args.master_port)
return args.host, args.clients, args.hatch_rate
Expand All @@ -54,12 +55,12 @@ def parse_arguments():

rsrc = resource.RLIMIT_NOFILE
soft, hard = resource.getrlimit(rsrc)
print 'RLIMIT_NOFILE soft limit starts as :', soft
print('RLIMIT_NOFILE soft limit starts as :', soft)

#resource.setrlimit(rsrc, (65535, hard)) #limit to one kilobyte

soft, hard = resource.getrlimit(rsrc)
print 'RLIMIT_NOFILE soft limit changed to :', soft
print('RLIMIT_NOFILE soft limit changed to :', soft)

def getEnviron(key,default):
if key in os.environ:
Expand All @@ -72,19 +73,19 @@ class SeldonJsLocust(TaskSet):


def get_token(self):
print "Getting access token"
print("Getting access token")
r = self.client.request("POST","/oauth/token",headers={"Accept":"application/json"},data={"grant_type":"client_credentials"},auth=(self.oauth_key,self.oauth_secret))
if r.status_code == 200:
j = json.loads(r.content)
self.access_token = j["access_token"]
print "got access token "+self.access_token
print("got access token "+self.access_token)
else:
print "failed to get access token"
print("failed to get access token")
sys.exit(1)


def on_start(self):
print "on_start"
print("on_start")
self.oauth_enabled = getEnviron('OAUTH_ENABLED',"true")
self.oauth_key = getEnviron('OAUTH_KEY',"key")
self.oauth_secret = getEnviron('OAUTH_SECRET',"secret")
Expand All @@ -109,20 +110,20 @@ def sendFeedback(self,response):
else:
self.routeRewards[route] = 0.5
rewardProba = self.routeRewards[route]
print route,rewardProba
print(route,rewardProba)
if random()>rewardProba:
j = {"response":response,"reward":1.0}
else:
j = {"response":response,"reward":0}
jStr = json.dumps(j)
r = self.client.request("POST",self.path_prefix+"/api/v0.1/feedback",headers={"Content-Type":"application/json","Accept":"application/json","Authorization":"Bearer "+self.access_token},name="feedback",data=jStr)
if not r.status_code == 200:
print "Failed feedback request "+str(r.status_code)
print("Failed feedback request "+str(r.status_code))
if r.status_code == 401:
if self.oauth_enabled == "true":
self.get_token()
else:
print r.headers
print(r.headers)
r.raise_for_status()


Expand All @@ -138,12 +139,12 @@ def getPrediction(self):
j = json.loads(r.content)
self.sendFeedback(j)
else:
print "Failed prediction request "+str(r.status_code)
print("Failed prediction request "+str(r.status_code))
if r.status_code == 401:
if self.oauth_enabled == "true":
self.get_token()
else:
print r.headers
print(r.headers)
r.raise_for_status()

class WebsiteUser(HttpLocust):
Expand Down

0 comments on commit 0a12441

Please sign in to comment.