import media # This program contrasts assignment when immutable and mutable objects are involved # First is an example with immutable objects (ints, here) a = 19 b = a a = 42 print a,b # prints 42 19 print "As you saw, this prints 42 and 19 - a and b associated with different objects" # here's an analogous example using mutable objects file_name = media.choose_file() a = media.load_picture(file_name) b = a for pixel in a: media.set_green(pixel,0) raw_input("enter 1 when you want to show a ") media.show(a) raw_input("enter 1 when you want to show b ") media.show(b) print "As you saw, a and b point to the same object - so you saw the same picture twice" # You will see exactly the same picture! # what if we want to display before and after pictures? You'll need # to have two copies of the picture. raw_input("enter 1 when you want to go on to the next example ") file_name = media.choose_file() a = media.load_picture(file_name) b = media.load_picture(file_name) # this replaces b = a for pixel in a: media.set_green(pixel,0) raw_input("when you want to see a, the 'after' picture, type 1 ") media.show(a) # The "after" picture raw_input("when