Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Dennis Lee Bieber Newsgroups: comp.lang.python Subject: Re: reading from a txt file Date: Thu, 26 Nov 2015 21:44:06 -0500 Organization: IISS Elusive Unicorn Lines: 66 Message-ID: References: <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> <1e567393-3750-43f2-8e7c-6e92f687ce9f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de O7VcRgptwwmWrO2y0RTQjwE9kRk8w3MG276MYTIHZjYA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:file': 0.07; "'0',": 0.09; 'brackets': 0.09; 'message-id:@4ax.com': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'itself.': 0.11; 'index': 0.13; 'result.': 0.15; 'thu,': 0.15; '"word"': 0.16; "['1',": 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:txt': 0.16; 'element': 0.18; 'url:home': 0.18; 'input': 0.18; '>>>': 0.20; '2015': 0.20; 'converted': 0.22; 'see:': 0.22; 'seems': 0.23; 'elements': 0.23; 'words': 0.24; 'header:X-Complaints-To:1': 0.26; 'helpful': 0.27; "skip:' 10": 0.28; 'lot.': 0.29; "i'm": 0.30; 'print': 0.30; 'code': 0.30; 'skip:[ 10': 0.31; 'word.': 0.33; 'file': 0.34; 'list': 0.34; 'could': 0.35; 'formats': 0.35; 'nov': 0.35; 'skip:> 10': 0.35; 'but': 0.36; 'list,': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'being': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'identify': 0.61; 'sample': 0.63; 'again!': 0.84; 'dennis': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: adsl-108-79-219-161.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99621 On Thu, 26 Nov 2015 17:24:38 -0800 (PST), Pedro Vincenty declaimed the following: >All were really helpful thanks a lot. Now I'm interested in identifying a particular index after being able to print out each word. Printing each word to the console I have : > >['METEOSAT-7'] >['1', '24932U', '97049B', '15319.57839525', '.00000058', '00000-0', '00000+0', '0', '9994'] >['2', '24932', '9.9015', '42.7484', '0001500', '224.8381', '52.7416', '1.00266716', '66645'] > >It seems awkward because I was expecting to have brackets only outside of all the words. I would like to identify one of these words. Thanks again! It would help to have the sample of the input file and the code used on it that generates this result. I see: * a one element list * a nine element list -- with some elements having invalid formats for Python numbers * a nine element list, though all fields can be converted to numeric types This could be the result of printing each "line" of words, but not from printing each "word" itself. >>> INPUT = "METEOSAT-7\n1 24932U 97049B 15319.57839525 .00000058 00000-0 00000+0 0 9994\n2 24932 9.9015 42.7484 0001500 224.8381 52.7416 1.00266716 66645" >>> >>> for ln in INPUT.split("\n"): ... words = ln.split() ... print ln ... print words ... for wd in words: ... print wd ... METEOSAT-7 ['METEOSAT-7'] METEOSAT-7 1 24932U 97049B 15319.57839525 .00000058 00000-0 00000+0 0 9994 ['1', '24932U', '97049B', '15319.57839525', '.00000058', '00000-0', '00000+0', '0', '9994'] 1 24932U 97049B 15319.57839525 .00000058 00000-0 00000+0 0 9994 2 24932 9.9015 42.7484 0001500 224.8381 52.7416 1.00266716 66645 ['2', '24932', '9.9015', '42.7484', '0001500', '224.8381', '52.7416', '1.00266716', '66645'] 2 24932 9.9015 42.7484 0001500 224.8381 52.7416 1.00266716 66645 >>> -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/