first off new to python and not good at it... I am trying to open a txt file called bestsellers.txt. In the text file it is split by a tab character for example,
1st to Die James Patterson Little, Brown 3/25/2001 Fiction
So, after Die it is tab spaced same with after patterson and brown and 2001
All I have right now is
openBook = open('bestsellers.txt', 'r')
booklist = openBook.split('\t')
But, it doesn't seem to work, suggestions on what to do? I have to keep it simple.
I know this is probably a dumb question as well, so I apologize...
解决方案
To split at each tab, iterate over the file like so:
data = [i.strip('\n').split('\t') for i in open('bestsellers.txt')]