On 11/26/2015 12:34 PM, vincentype...@gmail.com wrote:
Hey, I'm wondering how to read individual strings in a text file. I can read a text file by lines with .readlines() , but I need to read specifically by strings, not including spaces. Thanks in advance
Read the lines with readlines(), as you say, then split each line into whatever pieces you want with split (or with any of the many other string methods).
A minimal example (without readlines): >>> lines = ['a b c', 'aa bb cc'] >>> for line in lines: ... words = line.split() ... print(words) ... ['a', 'b', 'c'] ['aa', 'bb', 'cc'] -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418 -- https://mail.python.org/mailman/listinfo/python-list