Why doesn't sys.stdout.write work in python2?
Question: 
    #!/usr/bin/python
    import sys
    
    def main():
    
        f=open("a",'r')
        line1=f.readlines()
        f.close()
    
        try:
            sys.stdout.write(line1)
        except:
            print "?"
    if __name__ == "__main__":
        main()
    


Answer: `f.readlines()` doesn't return a single string, it returns a _list of lines_.
Even if there's only one line! So `sys.stdout.write()` doesn't know how to
handle that. If you iterate over that list of lines, and try to write each
one, it works just fine:

    
    
    #!/usr/bin/python
    import sys
    
    def main():
    
        f = open("a",'r')
        lines = f.readlines()  # lines is actually a list
        f.close()
    
        print lines  # You'll see your issue, here!
        try:
            for line in lines:
                sys.stdout.write(line)  # Works now
        except:
            print "?"
    
    if __name__ == "__main__":
        main()
    

