[Tutor] A quick question

Edy Lie ed@iterunet.com
Sat, 10 Nov 2001 01:33:18 +0800


This is a multi-part message in MIME format.

------=_NextPart_000_0010_01C16987.ACB09680
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi everyone

   I was thinking to change the following codes to python but aint sure =
how should i approach it.

Btw these are the codes

  open (SEARCH, "$file") or die switch();
   while ($line =3D <SEARCH>) {
      if ($line =3D~ /$domain/i) {
         print "Found ... \n\n";
         for ($x=3D0; $x<5; $x++){
            $line =3D <SEARCH>;
            print $line;
            }
        }
}


I have declared the=20

def search(self, filename=3D'record.txt'):
        f =3D open(filename,'r')
        f.readlines()
        f.close()

and my search part is like=20

print 'Searching New User\n'
   UserInput =3D raw_input("Search for text: ")
   SearchInput =3D string.split(UserInput) #create a list of tokens by =
spliting the search-string at each space (" ")
   ReString =3D string.join(SearchInput, "\n+")
   add =3D DataBase()


Thanks :)
Regards,
Edy Lie

------=_NextPart_000_0010_01C16987.ACB09680
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 5.50.4807.2300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi everyone</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp; I was thinking to change =
the following=20
codes to python but aint sure how should i approach it.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Btw these are the codes</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; open (SEARCH, "$file") or die=20
switch();<BR>&nbsp;&nbsp; while ($line =3D &lt;SEARCH&gt;)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($line =3D~ /$domain/i)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "Found ...=20
\n\n";<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ($x=3D0; =
$x&lt;5;=20
$x++){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
$line =3D=20
&lt;SEARCH&gt;;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;=20
print=20
$line;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
}</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have declared the </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>def search(self,=20
filename=3D'record.txt'):<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
f =3D=20
open(filename,'r')<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
f.readlines()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
f.close()<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>and my search part is like =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>print 'Searching New =
User\n'<BR>&nbsp;&nbsp;=20
UserInput =3D raw_input("Search for text: ")<BR>&nbsp;&nbsp; SearchInput =
=3D=20
string.split(UserInput) #create a list of tokens by spliting the =
search-string=20
at each space (" ")<BR>&nbsp;&nbsp; ReString =3D =
string.join(SearchInput,=20
"\n+")<BR>&nbsp;&nbsp; add =3D DataBase()<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks :)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Regards,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Edy Lie</DIV></FONT></BODY></HTML>

------=_NextPart_000_0010_01C16987.ACB09680--