Anyone know the solution
Cameron Simpson
cs at zip.com.au
Tue Oct 28 20:53:46 EDT 2014
More information about the Python-list mailing list
Tue Oct 28 20:53:46 EDT 2014
- Previous message (by thread): Anyone know the solution
- Next message (by thread): Anyone know the solution
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 28Oct2014 09:07, ngangsia akumbo <ngangsia at gmail.com> wrote: >This is a sample code on how to read data from a file > >files1 {} > >result = open("file1.txt") >for line in result: > file1 = line>split() >files1.append(file1) >result.close() >file1.sort() >file1.reverse() > >print('THE FILE INFO') > >print(file1(0) >print(file1(1) Do you have a specific question to accompany this? The code above is syntactly invalid, so it will not run. The line: files1 {} is invalid, but looks like it is intended to initialise files1 as a dictionary. However, the rest of the program seems to use it as though it were a list. The line: file1 = line>split() should probably be written: file1 = line.split() With ">" it is legal (as it performs a comparison) but will fail because there's no bare "split()" function, and anyway is probably not as intended. Your final print statements need an extra closing parenthesis each. Cheers, Cameron Simpson <cs at zip.com.au> I fit in my suit, my suit fits in my suitcase, hence i fit in my suitcase. - Cees Keyer <cees at htsa.hva.nl>
- Previous message (by thread): Anyone know the solution
- Next message (by thread): Anyone know the solution
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list