Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79863

Re: Anyone know the solution

Date 2014-10-29 11:53 +1100
From Cameron Simpson <cs@zip.com.au>
Subject Re: Anyone know the solution
References <f9c39375-d0ff-4f16-aa05-6d8c8fdf7267@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.15274.1414544041.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 28Oct2014 09:07, ngangsia akumbo <ngangsia@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@zip.com.au>

I fit in my suit, my suit fits in my suitcase, hence i fit in my suitcase.
         - Cees Keyer <cees@htsa.hva.nl>

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Anyone know the solution emmanueloje@gmail.com - 2014-10-27 08:10 -0700
  Re: Anyone know the solution alister <alister.nospam.ware@ntlworld.com> - 2014-10-27 15:21 +0000
  Re: Anyone know the solution Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-27 11:20 -0400
  Re: Anyone know the solution Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-27 20:18 -0400
  Re: Anyone know the solution Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-28 00:20 +0000
  Re: Anyone know the solution alex23 <wuwei23@gmail.com> - 2014-10-28 10:33 +1000
    Re: Anyone know the solution Anton <anton.schattenfeld@gmail.com> - 2014-10-28 18:28 -0700
      Re: Anyone know the solution alex23 <wuwei23@gmail.com> - 2014-10-29 12:03 +1000
      Re: Anyone know the solution Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-10-29 18:13 +1300
        Re: Anyone know the solution Anton <anton.schattenfeld@gmail.com> - 2014-10-29 17:09 -0700
  Re: Anyone know the solution Terry Reedy <tjreedy@udel.edu> - 2014-10-28 00:24 -0400
    Re: Anyone know the solution "Mario R. Osorio" <nimbiotics@gmail.com> - 2014-10-28 08:38 -0700
  Re: Anyone know the solution ngangsia akumbo <ngangsia@gmail.com> - 2014-10-28 09:07 -0700
    Re: Anyone know the solution Cameron Simpson <cs@zip.com.au> - 2014-10-29 11:53 +1100
    Re: Anyone know the solution Dave Angel <davea@davea.name> - 2014-10-28 22:11 -0400
  Re: Anyone know the solution Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-29 18:03 +0000

csiph-web