I am curious how this Try and Except work in python after running into this error:
def for_file(data):
    open_file = file('data.txt', 'w')
    try:
        open_file.write(data)
    except:
           print 'This is an error!'
    open_file.close()
Output: This is an error!
def for_file(data):
    try:
        open_file = file('data.txt', 'w')
        open_file.write(data)
        print 'Successful!'
    except:
           print 'This is an error!'
    open_file.close()
Output: Successful!
How is it possible?
Error: 'ascii' codec can't encode characters in position 15-16: ordinal not in range(128)
I am receiving data in unicode form. what should I do?
 
     
    