Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'function,': 0.09; 'line:': 0.09; 'performs': 0.09; 'statements': 0.09; 'subject:Anyone': 0.09; 'anyway': 0.14; 'dictionary.': 0.16; 'file1': 0.16; 'fits': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'intended.': 0.16; 'line.split()': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'simpson': 0.16; 'skip:> 20': 0.16; 'wrote:': 0.18; 'fit': 0.20; 'seems': 0.21; 'print': 0.22; 'this?': 0.23; 'header:User- Agent:1': 0.23; 'cheers,': 0.24; 'looks': 0.24; 'question': 0.24; 'header:In-Reply-To:1': 0.27; 'rest': 0.29; 'code': 0.31; 'file': 0.32; 'probably': 0.32; 'subject:the': 0.34; 'but': 0.35; 'received:com.au': 0.36; 'skip:> 10': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'list.': 0.37; 'received:211': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'content-disposition:inline': 0.62; 'sample': 0.67; 'legal': 0.71; 'accompany': 0.84; 'bare': 0.84; 'subject:know': 0.84 Date: Wed, 29 Oct 2014 11:53:46 +1100 From: Cameron Simpson To: python-list@python.org Subject: Re: Anyone know the solution MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) References: X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=fvDlOjIf c=1 sm=1 tr=0 a=YuQlxtEQCowy2cfE5kc7TA==:117 a=YuQlxtEQCowy2cfE5kc7TA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=LcaDllckn3IA:10 a=r5UFkecV8NkA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=pGLkceISAAAA:8 a=uGQ_b2ZQJEks2-rZxb8A:9 a=CjuIK1q_8ugA:10 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414544041 news.xs4all.nl 2883 [2001:888:2000:d::a6]:51119 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79863 On 28Oct2014 09:07, ngangsia akumbo 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 I fit in my suit, my suit fits in my suitcase, hence i fit in my suitcase. - Cees Keyer