Cameron Simpson wrote: > In Python 3 the loop is much cleaner: > > with open('namelist.txt', encoding='utf-8') as f: > for line in f: > line = line.strip() > print("line =", line)
In Python 2.7 you can use io.open(): import io with io.open('namelist.txt', encoding='utf-8') as f: for line in f: line = line.strip() print "line =", line However, if you have the choice go with Python 3 which is where all improvements to the language and its libraries go. -- https://mail.python.org/mailman/listinfo/python-list