[Tutor] printing a word in the second line of a text tile
tonycervone
tonycervone@netzero.net
Thu, 18 Oct 2001 05:40:37 -0400
This is a multi-part message in MIME format.
------=_NextPart_000_0016_01C15797.6A2D0CA0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I want to thank those who replied to my first question, how to print a =
word in the first line of a text file. How about if I want to print a =
word according to any location in the second line of a text. That is, I =
want to read the first two lines of a text file, and then print the =
first word of the second line of the file. i am using the following:
inp =3D open( 'filename')
line =3D inp.readlines()
print =3D line.split()[position]
and I get an " attributeError: split" error . thanks again. tony
----- Original Message -----=20
From: alan.gauld@bt.com=20
To: tonycervone@netzero.net=20
Sent: Thursday, October 18, 2001 4:27 AM
Subject: RE: [Tutor] printing a word in a line
Alan, after entering the first line of your script, I get a "name =
error: there is no variable named popen"
Sorry, typo. It should be 'open' not 'popen'
BTW thanks for the book feedback, its always welcome.=20
I'm planning a second edition after I finish my current=20
book late next year, so I will include some stuuff on=20
using glob and navigating directories etc.
I already planned on some web programming stuff and=20
more on GUIs.
Alan G
------=_NextPart_000_0016_01C15797.6A2D0CA0
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>I want to thank those who replied to my =
first=20
question, how to print a word in the first line of a text file. How =
about if I=20
want to print a word according to any location in the second line =
of =20
a text. That is, I want to read the first two lines of a text file, and =
then=20
print the first word of the second line of the file. i am using =
the=20
following:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>inp =3D open( 'filename')</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>line =3D inp.readlines()</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>print =3D =
line.split()[position]</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>and I get an " attributeError: split" =
error .=20
thanks again. tony</FONT></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>----- Original Message ----- </DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV=20
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
<A title=3Dalan.gauld@bt.com=20
href=3D"mailto:alan.gauld@bt.com">alan.gauld@bt.com</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dtonycervone@netzero.net=20
href=3D"mailto:tonycervone@netzero.net">tonycervone@netzero.net</A> =
</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Thursday, October 18, =
2001 4:27=20
AM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> RE: [Tutor] printing a =
word in a=20
line</DIV>
<DIV><BR></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px =
solid; MARGIN-RIGHT: 0px">
<DIV><FONT face=3DArial size=3D2>Alan, after entering the first line =
of your=20
script, I get a "name error: there is no variable named =
popen"</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
class=3D010362408-18102001>Sorry, typo. It should be 'open' not=20
'popen'</SPAN></FONT></DIV>
<DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
class=3D010362408-18102001></SPAN></FONT> </DIV>
<DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
class=3D010362408-18102001>BTW thanks for the book feedback, its =
always=20
welcome. </SPAN></FONT></DIV>
<DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
class=3D010362408-18102001>I'm planning a second edition after I =
finish my=20
current </SPAN></FONT></DIV>
<DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
class=3D010362408-18102001>book late next year, so I will include =
some stuuff=20
on </SPAN></FONT></DIV>
<DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
class=3D010362408-18102001>using glob and navigating directories=20
etc.</SPAN></FONT></DIV>
<DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
class=3D010362408-18102001></SPAN></FONT> </DIV>
<DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
class=3D010362408-18102001>I already planned on some web programming =
stuff and=20
</SPAN></FONT></DIV>
<DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
class=3D010362408-18102001>more on GUIs.</SPAN></FONT></DIV>
<DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
class=3D010362408-18102001></SPAN></FONT> </DIV>
<DIV><FONT face=3D"Courier New" color=3D#0000ff size=3D2><SPAN=20
class=3D010362408-18102001>Alan G</SPAN></FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV=20
style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff =
2px solid; MARGIN-RIGHT: =
0px"> </DIV></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_0016_01C15797.6A2D0CA0--
----------------------------------------------------
Sign Up for NetZero Platinum Today
Only $9.95 per month!
http://my.netzero.net/s/signup?r=platinum&refcd=PT97