[Tutor] More help needed in sorting files and strings

tonycervone tonycervone@netzero.net
Sat, 27 Oct 2001 06:54:43 -0400


This is a multi-part message in MIME format.

------=_NextPart_000_0007_01C15EB4.4202F9A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi all.=20

I have been using this code to read weather reports and to print only =
the first two stations symbols in the file:
       inp =3Dopen("Metar\Infometar.txt")
       lines =3D inp.readlines()
       Depart =3D lines[1].split()[0]
       Destin =3D lines[4].split()[0]
       Destin1 =3D lines[5].split()[0]
       Print Depart+" "+Destin+" "+Destin1

This code  works fine until it finds an empty line and then I get an out =
of range error. Here's why:

2001/10/23 21:18
KPVD 232118Z AUTO 22014KT 3/4SM +TSRA BKN021 OVC033 20/14 A2937
          RMK AO2

2001/10/23 21:18
KLGA 232118Z AUTO 23008KT 6SM -SHRA BKN012 18/17 A2962 RMK
         AO2

2001/10/23 21:18
KBDL 232118Z AUTO 01012KT 6SM RA OVC050 14/05 A2965 RMK AO2

In the example above, the Depart =3D lines[1].split()[0] always works =
because all files start that way. The code will print out KPVD =
2001/10/23 KLGA. This is perfect if all reports contained the same =
number of lines. If, however, another report has all the information =
contained in two lines instead ot three, the Destin1 =3D =
lines[5].split()[0] will give me an out of range error, and the Destin =
=3D lines[4].split()[0] will give me 2001/10/23 instead of KLGA.

So this is where I get lost. It would seem that a simple" if condition" =
checking for either a null string or something other than a null would =
do the trick. i would then replace the actual numbers in the bracket s =
with variables that would point to the correct line. The problem is that =
I cannot use the line[].split()[] statement to do the checking without =
first getting the "out of range error" in an if condition. What other =
"simple" routine can I use to ensure avoidance of that error? thank you. =
tony



------=_NextPart_000_0007_01C15EB4.4202F9A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi all. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have been using this code to read =
weather reports=20
and to print only the first two stations symbols in the =
file:</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inp=20
=3Dopen("Metar\Infometar.txt")<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
lines =3D=20
inp.readlines()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Depart =3D=20
lines[1].split()[0]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Destin =3D=20
lines[4].split()[0]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Destin1 =3D=20
lines[5].split()[0]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Print =
Depart+"=20
"+Destin+" "+Destin1</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This code &nbsp;works fine until it =
finds an empty=20
line and then I get an out of range error. Here's why:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>2001/10/23 21:18<BR>KPVD 232118Z AUTO =
22014KT 3/4SM=20
+TSRA BKN021 OVC033 20/14=20
A2937<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RMK =

AO2</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>2001/10/23 21:18<BR>KLGA 232118Z AUTO =
23008KT 6SM=20
-SHRA BKN012 18/17 A2962 =
RMK<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
AO2</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>2001/10/23 21:18<BR>KBDL 232118Z AUTO =
01012KT 6SM=20
RA OVC050 14/05 A2965 RMK AO2<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>In the example above, the Depart =3D=20
lines[1].split()[0] always works because all files start that way. The =
code will=20
print out KPVD 2001/10/23 KLGA. This is perfect if all reports contained =
the=20
same number of lines.&nbsp;If, however, another report has all the =
information=20
contained in&nbsp;two lines instead ot three, the Destin1 =3D =
lines[5].split()[0]=20
will give me an out of range error, and the Destin =3D =
lines[4].split()[0] will=20
give me 2001/10/23 instead of KLGA.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV><FONT face=3DArial =
size=3D2>
<DIV>So this is where I get lost. It would seem that a simple" if =
condition"=20
checking for either a null string or something other than a null would =
do the=20
trick. i would then replace the actual numbers in the bracket s with =
variables=20
that would point to the correct line. The problem is that I cannot use =
the=20
line[].split()[] statement to do the checking without first getting the =
"out of=20
range error" in an if condition. What other "simple" routine can I use =
to ensure=20
avoidance of that error? thank you. =
tony<BR><BR></DIV></FONT></BODY></HTML>

------=_NextPart_000_0007_01C15EB4.4202F9A0--

----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97