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


Groups > comp.lang.python > #99621

Re: reading from a txt file

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Newsgroups comp.lang.python
Subject Re: reading from a txt file
Date 2015-11-26 21:44 -0500
Organization IISS Elusive Unicorn
Message-ID <mailman.161.1448592253.20593.python-list@python.org> (permalink)
References <175ab5d2-d8e3-44e7-a71f-88b3153daf89@googlegroups.com> <1e567393-3750-43f2-8e7c-6e92f687ce9f@googlegroups.com>

Show all headers | View raw


On Thu, 26 Nov 2015 17:24:38 -0800 (PST), Pedro Vincenty
<vincentypedro@gmail.com> 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/

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


Thread

reading from a txt file vincentypedro@gmail.com - 2015-11-26 12:34 -0800
  Re: reading from a txt file Denis McMahon <denismfmcmahon@gmail.com> - 2015-11-26 20:50 +0000
  Re: reading from a txt file Jason Friedman <jsf80238@gmail.com> - 2015-11-26 14:04 -0700
  Re: reading from a txt file Gary Herron <gherron@digipen.edu> - 2015-11-26 13:01 -0800
  Re: reading from a txt file Pedro Vincenty <vincentypedro@gmail.com> - 2015-11-26 17:24 -0800
    Re: reading from a txt file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-26 21:44 -0500

csiph-web