Just started working with Python today, so if I'm doing something crazy here please let me know. I have been working to simplify a block of code so that I can more easily reuse it. My goal would be to just update one set of variables during each reuse. The last working code I had is this:
class_a='amstaff'
class_b='beagle'
class_c='doberman'
class_d='germanshepherd'
class_e='rottweiler'
with open(file_path +class_a+'.zip', 'rb') as class_a, open(file_path +class_b+'.zip', 'rb') as class_b, open(file_path +class_c+'.zip', 'rb') as class_c, open(file_path +class_d+'.zip', 'rb') as class_d, open(file_path +class_e+'.zip', 'rb') as class_e:
model = visual_recognition.create_classifier(
classifier_name,
amstaff_positive_examples=class_a,
beagle_positive_examples=class_b,
doberman_positive_examples=class_c,
germanshepherd_positive_examples=class_d,
rottweiler_positive_examples=class_e)
print(json.dumps(model, indent=2))
This saves me a ton of time from my original code but still requires a fair bit of editing. So I was thinking I might be able to use a for loop but I got stuck about halfway through. Here's what I have so far, but I am stumped on how to proceed from here.
classes=["amstaff", "beagle", "doberman", "germanshepherd", "rottweiler"]
for x in classes:
with open(file_path +x+'.zip', 'rb') as x:
model = visual_recognition.create_classifier(
classifier_name,
amstaff_positive_examples=class_a,
beagle_positive_examples=class_b,
doberman_positive_examples=class_c,
germanshepherd_positive_examples=class_d,
rottweiler_positive_examples=class_e)
print(json.dumps(model, indent=2))