Change "print " lines to "print(" lines

This commit is contained in:
ddxtanx 2017-10-05 21:03:30 -05:00
parent 5c1a8f9a32
commit 384915d5a7
9 changed files with 188 additions and 305 deletions

View file

@ -44,7 +44,7 @@ def get_configuration(sys_argv):
try: try:
opts, args = getopt.getopt(sys_argv[1:], 'hlmpwstqao:') opts, args = getopt.getopt(sys_argv[1:], 'hlmpwstqao:')
except getopt.GetoptError as err: except getopt.GetoptError as err:
print str(err) print(str(err))
sys.exit(2) sys.exit(2)
config = { config = {
"file" : None, "file" : None,
@ -63,7 +63,7 @@ def get_configuration(sys_argv):
} }
for opt, arg in opts: for opt, arg in opts:
if opt == '-h': if opt == '-h':
print HELP_MESSAGE print(HELP_MESSAGE)
return return
if opt in ['-l', '-p']: if opt in ['-l', '-p']:
config["camera_config"] = LOW_QUALITY_CAMERA_CONFIG config["camera_config"] = LOW_QUALITY_CAMERA_CONFIG
@ -93,7 +93,7 @@ def get_configuration(sys_argv):
config["skip_animations"] = config["save_image"] and not config["write_to_movie"] config["skip_animations"] = config["save_image"] and not config["write_to_movie"]
if len(args) == 0: if len(args) == 0:
print HELP_MESSAGE print(HELP_MESSAGE)
sys.exit() sys.exit()
config["file"] = args[0] config["file"] = args[0]
if len(args) > 1: if len(args) > 1:
@ -129,7 +129,7 @@ def prompt_user_for_choice(name_to_obj):
num_to_name = {} num_to_name = {}
names = sorted(name_to_obj.keys()) names = sorted(name_to_obj.keys())
for count, name in zip(it.count(1), names): for count, name in zip(it.count(1), names):
print "%d: %s"%(count, name) print("%d: %s"%(count, name))
num_to_name[count] = name num_to_name[count] = name
try: try:
user_input = raw_input(CHOOSE_NUMBER_MESSAGE) user_input = raw_input(CHOOSE_NUMBER_MESSAGE)
@ -138,19 +138,19 @@ def prompt_user_for_choice(name_to_obj):
for num_str in user_input.split(",") for num_str in user_input.split(",")
] ]
except: except:
print INVALID_NUMBER_MESSAGE print(INVALID_NUMBER_MESSAGE)
sys.exit() sys.exit()
def get_scene_classes(scene_names_to_classes, config): def get_scene_classes(scene_names_to_classes, config):
if len(scene_names_to_classes) == 0: if len(scene_names_to_classes) == 0:
print NO_SCENE_MESSAGE print(NO_SCENE_MESSAGE)
return [] return []
if len(scene_names_to_classes) == 1: if len(scene_names_to_classes) == 1:
return scene_names_to_classes.values() return scene_names_to_classes.values()
if config["scene_name"] in scene_names_to_classes: if config["scene_name"] in scene_names_to_classes:
return [scene_names_to_classes[config["scene_name"]] ] return [scene_names_to_classes[config["scene_name"]] ]
if config["scene_name"] != "": if config["scene_name"] != "":
print SCENE_NOT_FOUND_MESSAGE print(SCENE_NOT_FOUND_MESSAGE)
return [] return []
if config["write_all"]: if config["write_all"]:
return scene_names_to_classes.values() return scene_names_to_classes.values()
@ -206,15 +206,11 @@ def main():
handle_scene(SceneClass(**scene_kwargs), **config) handle_scene(SceneClass(**scene_kwargs), **config)
play_finish_sound() play_finish_sound()
except: except:
print "\n\n" print("\n\n")
traceback.print_exc() traceback.print_exc()
print "\n\n" print("\n\n")
play_error_sound() play_error_sound()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -284,9 +284,9 @@ def generate_tex_file(expression, template_tex_file):
tex_hash(expression, template_tex_file) tex_hash(expression, template_tex_file)
) + ".tex" ) + ".tex"
if not os.path.exists(result): if not os.path.exists(result):
print "Writing \"%s\" to %s"%( print("Writing \"%s\" to %s"%(
"".join(expression), result "".join(expression), result
) ))
with open(template_tex_file, "r") as infile: with open(template_tex_file, "r") as infile:
body = infile.read() body = infile.read()
body = body.replace(TEX_TEXT_TO_REPLACE, expression) body = body.replace(TEX_TEXT_TO_REPLACE, expression)
@ -345,17 +345,3 @@ def dvi_to_svg(dvi_file, regen_if_exists = False):
] ]
os.system(" ".join(commands)) os.system(" ".join(commands))
return result return result

View file

@ -92,10 +92,10 @@ class Network(object):
for mini_batch in mini_batches: for mini_batch in mini_batches:
self.update_mini_batch(mini_batch, eta) self.update_mini_batch(mini_batch, eta)
if test_data: if test_data:
print "Epoch {0}: {1} / {2}".format( print("Epoch {0}: {1} / {2}".format(
j, self.evaluate(test_data), n_test) j, self.evaluate(test_data), n_test))
else: else:
print "Epoch {0} complete".format(j) print("Epoch {0} complete".format(j))
def update_mini_batch(self, mini_batch, eta): def update_mini_batch(self, mini_batch, eta):
"""Update the network's weights and biases by applying """Update the network's weights and biases by applying
@ -215,7 +215,7 @@ def test_network():
n_right += 1 n_right += 1
else: else:
n_wrong += 1 n_wrong += 1
print n_right, n_wrong, float(n_right)/(n_right + n_wrong) print(n_right, n_wrong, float(n_right)/(n_right + n_wrong))
def layer_to_image_array(layer): def layer_to_image_array(layer):
w = int(np.ceil(np.sqrt(len(layer)))) w = int(np.ceil(np.sqrt(len(layer))))
@ -254,8 +254,8 @@ def maximizing_input(network, layer_index, layer_vect, n_steps = 100, seed_guess
norms.append(norm) norms.append(norm)
old_pre_sig_guess = np.array(pre_sig_guess) old_pre_sig_guess = np.array(pre_sig_guess)
pre_sig_guess += 0.1*gradient pre_sig_guess += 0.1*gradient
print np.linalg.norm(old_pre_sig_guess - pre_sig_guess) print(np.linalg.norm(old_pre_sig_guess - pre_sig_guess))
print "" print("")
return sigmoid(pre_sig_guess) return sigmoid(pre_sig_guess)
def save_organized_images(n_images_per_number = 10): def save_organized_images(n_images_per_number = 10):
@ -299,41 +299,3 @@ def get_organized_images():
# prev_vect /= np.max(np.abs(prev_vect)) # prev_vect /= np.max(np.abs(prev_vect))
# # prev_vect /= 1.1 # # prev_vect /= 1.1
# return maximizing_input(network, layer_index - 1, prev_vect) # return maximizing_input(network, layer_index - 1, prev_vect)

View file

@ -145,7 +145,7 @@ def get_hand_map(which_hand = "right"):
elif which_hand == "left": elif which_hand == "left":
Class = LeftHand Class = LeftHand
else: else:
print "Bad arg, bro" print("Bad arg, bro")
return return
return dict([ return dict([
(num, Class(num, small=True)) (num, Class(num, small=True))
@ -170,7 +170,7 @@ class SaveEachNumber(OverHand):
Image.fromarray(self.frames[COUNT_TO_FRAME_NUM[count]]).save(path) Image.fromarray(self.frames[COUNT_TO_FRAME_NUM[count]]).save(path)
def write_to_movie(self, name = None): def write_to_movie(self, name = None):
print "Why bother writing to movie..." print("Why bother writing to movie...")
class ShowCounting(OverHand): class ShowCounting(OverHand):
def construct(self): def construct(self):
@ -197,7 +197,7 @@ class ShowFrameNum(OverHand):
def construct(self): def construct(self):
OverHand.construct(self) OverHand.construct(self)
for frame, count in zip(self.frames, it.count()): for frame, count in zip(self.frames, it.count()):
print count, "of", len(self.frames) print(count + "of" + len(self.frames))
mob = Mobject(*[ mob = Mobject(*[
TexMobject(char).shift(0.3*x*RIGHT) TexMobject(char).shift(0.3*x*RIGHT)
for char, x, in zip(str(count), it.count()) for char, x, in zip(str(count), it.count())
@ -480,14 +480,3 @@ class WithToes(Scene):
if __name__ == "__main__": if __name__ == "__main__":
command_line_create_scene(MOVIE_PREFIX) command_line_create_scene(MOVIE_PREFIX)

View file

@ -2671,7 +2671,7 @@ class SmoothBritainLogLogPlot(IntroduceLogLogPlot):
interim_point1 = p2[0]*RIGHT + p1[1]*UP interim_point1 = p2[0]*RIGHT + p1[1]*UP
interim_point2 = p4[0]*RIGHT + p3[1]*UP interim_point2 = p4[0]*RIGHT + p3[1]*UP
print self.func(2) print(self.func(2))
slope_lines1, slope_lines2 = VMobject(), VMobject() slope_lines1, slope_lines2 = VMobject(), VMobject()
slope_lines1.set_points_as_corners( slope_lines1.set_points_as_corners(
@ -2956,19 +2956,3 @@ class Thumbnail(Scene):
koch_curve.to_edge(DOWN, buff = SMALL_BUFF) koch_curve.to_edge(DOWN, buff = SMALL_BUFF)
self.add(koch_curve, title) self.add(koch_curve, title)

View file

@ -105,7 +105,7 @@ class BufferedCounting(SceneFromVideo):
for dim, spread in zip(self.shape, spreads) for dim, spread in zip(self.shape, spreads)
] ]
for frame, index in zip(self.frames, it.count()): for frame, index in zip(self.frames, it.count()):
print index, "of", len(self.frames) print(index + "of" + len(self.frames))
blurred = cv2.GaussianBlur(frame, ksize, sigmaX) blurred = cv2.GaussianBlur(frame, ksize, sigmaX)
edged = cv2.Canny(blurred, threshold1, threshold2) edged = cv2.Canny(blurred, threshold1, threshold2)
buffed = reduce(np.dot, [matrices[0], edged, matrices[1]]) buffed = reduce(np.dot, [matrices[0], edged, matrices[1]])
@ -186,7 +186,7 @@ class ShowCounting(SceneFromVideo):
SceneFromVideo.construct(self, path) SceneFromVideo.construct(self, path)
total_time = len(self.frames)*self.frame_duration total_time = len(self.frames)*self.frame_duration
for count in range(32): for count in range(32):
print count print(count)
mob = TexMobject(str(count)).scale(1.5) mob = TexMobject(str(count)).scale(1.5)
mob.shift(0.3*LEFT).to_edge(UP, buff = 0.1) mob.shift(0.3*LEFT).to_edge(UP, buff = 0.1)
index_range = range( index_range = range(
@ -210,7 +210,7 @@ class ShowFrameNum(SceneFromVideo):
path = os.path.join(MOVIE_DIR, MOVIE_PREFIX, filename+".mp4") path = os.path.join(MOVIE_DIR, MOVIE_PREFIX, filename+".mp4")
SceneFromVideo.construct(self, path) SceneFromVideo.construct(self, path)
for frame, count in zip(self.frames, it.count()): for frame, count in zip(self.frames, it.count()):
print count, "of", len(self.frames) print(count + "of" + len(self.frames))
mob = Mobject(*[ mob = Mobject(*[
TexMobject(char).shift(0.3*x*RIGHT) TexMobject(char).shift(0.3*x*RIGHT)
for char, x, in zip(str(count), it.count()) for char, x, in zip(str(count), it.count())

View file

@ -158,11 +158,11 @@ class TestZetaOnHalfPlane(ZetaTransformationScene):
self.add_transformable_plane() self.add_transformable_plane()
self.add_extra_plane_lines_for_zeta() self.add_extra_plane_lines_for_zeta()
self.prepare_for_transformation(self.plane) self.prepare_for_transformation(self.plane)
print sum([ print(sum([
mob.get_num_points() mob.get_num_points()
for mob in self.plane.family_members_with_points() for mob in self.plane.family_members_with_points()
]) ]))
print len(self.plane.family_members_with_points()) print(len(self.plane.family_members_with_points()))
self.apply_zeta_function() self.apply_zeta_function()
self.dither() self.dither()
@ -3359,8 +3359,3 @@ class ZetaPartialSums(ZetaTransformationScene):
Transform(symbol, sigma) Transform(symbol, sigma)
) )
self.dither() self.dither()

View file

@ -471,7 +471,7 @@ class Scene(object):
name = str(self) name = str(self)
file_path = self.get_movie_file_path(name, ".mp4") file_path = self.get_movie_file_path(name, ".mp4")
temp_file_path = file_path.replace(".mp4", "Temp.mp4") temp_file_path = file_path.replace(".mp4", "Temp.mp4")
print "Writing to %s"%temp_file_path print("Writing to %s"%temp_file_path)
self.args_to_rename_file = (temp_file_path, file_path) self.args_to_rename_file = (temp_file_path, file_path)
fps = int(1/self.frame_duration) fps = int(1/self.frame_duration)
@ -502,29 +502,3 @@ class Scene(object):
shutil.move(*self.args_to_rename_file) shutil.move(*self.args_to_rename_file)
else: else:
os.rename(*self.args_to_rename_file) os.rename(*self.args_to_rename_file)

View file

@ -25,7 +25,7 @@ class SceneFromVideo(Scene):
start_frame, end_frame = map(lambda t : fps*t, time_range) start_frame, end_frame = map(lambda t : fps*t, time_range)
frame_count = end_frame - start_frame frame_count = end_frame - start_frame
print "Reading in " + file_name + "..." print("Reading in " + file_name + "...")
for count in show_progress(range(start_frame, end_frame+1)): for count in show_progress(range(start_frame, end_frame+1)):
returned, frame = cap.read() returned, frame = cap.read()
if not returned if not returned
@ -52,6 +52,3 @@ class SceneFromVideo(Scene):
for index in range(len(self.frames)): for index in range(len(self.frames)):
for i in range(3): for i in range(3):
self.frames[index][:,:,i] = edged_frames[index] self.frames[index][:,:,i] = edged_frames[index]