[Tutor] question about merging two programs

Bob Gailer bgailer@alum.rpi.edu
Wed May 7 10:23:07 2003


--=======484B4E7C=======
Content-Type: multipart/alternative; x-avg-checked=avg-ok-6D6F1DCD; boundary="=====================_2607469==.ALT"


--=====================_2607469==.ALT
Content-Type: text/plain; x-avg-checked=avg-ok-6D6F1DCD; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 06:27 AM 5/7/2003 -0700, Abdirizak abdi wrote:

>Hi,
>I was working on two separate programs one program for file indexing
>and another for searching the words, I was running them separately
>now I decided to put to together with a single main( ), I set up the 
>program to be run this way: (the main is shown below)
>
>first for indexing:
>C:\TestInd>index-02.py Test Doc.txt
>                  |-----------------|--------|-------------|
>                    prog           dir     file to be indexed
>
>Second for searching:
>C:\TestInd>index-02.py Test word
>                   |-----------------|--------|-------------|
>                     prog           dir     word to be searched
>
>Here is the main part set up to fit the two above possibilities:
>The searching part works but the indexing part when merged it doesn't
>work the program jumps to the else when searching but when asked for
>indexing it doesn't execute the top section, but it compiles without any
>error.  Can anyone spot any upnormalities specialy if I got it right the
>condition which evalutes  if argv[2] in [ '.txt' ] which means if the 
>argument contains substring  '.txt'
>
>here is the program
>
>def main(argv):
>     if len(argv) < 2:
>         sys.stderr.write(usage + "\n")
>         return 1
>     #------------------------
>     #Extension = argv[2]
>
>     if argv[2] in ['.txt']:

Replace this with
       if argv[2].find('.txt') >= 0:

>       #print argv[2]
>       indexdir = argv[1]
>       files = argv[2:]
>       myindexer = indexer(indexdir)
>       try:
>         for file in files:
>           print "indexing....", file,
>           sys.stdout.flush()
>           myindexer.index(file)
>           print "...done."
>       finally:
>         print "committing....",
>         sys.stdout.flush()
>         myindexer.commit()
>         print "....done."
>       return 0
>
>
>thanks in advance
>
>
>Do you Yahoo!?
><http://us.rd.yahoo.com/search/mailsig/*http://search.yahoo.com>The New 
>Yahoo! Search - Faster. Easier. Bingo.
>---
>Incoming mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.474 / Virus Database: 272 - Release Date: 4/18/2003

Bob Gailer
bgailer@alum.rpi.edu
303 442 2625


--=====================_2607469==.ALT
Content-Type: text/html; x-avg-checked=avg-ok-6D6F1DCD; charset=us-ascii
Content-Transfer-Encoding: 8bit

<html>
<body>
At 06:27 AM 5/7/2003 -0700, Abdirizak abdi wrote:<br><br>
<blockquote type=cite class=cite cite>Hi,<br>
I was working on two separate programs one program for file 
indexing<br>
and another for searching the words, I was running them separately<br>
now I decided to put to together with a single main( ), I set up the
program to be run this way: (the main is shown below)<br>
&nbsp;<br>
first for indexing:<br>
<b>C:\TestInd&gt;index-02.py Test Doc.txt</b><br>
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|-----------------|--------|-------------|</b><br>
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
prog&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
dir&nbsp;&nbsp;&nbsp;&nbsp; file to be indexed</b><br>
&nbsp;<br>
Second for searching:<br>
<b>C:\TestInd&gt;index-02.py Test word</b><br>
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
|-----------------|--------|-------------|</b><br>
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
prog&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
dir&nbsp;&nbsp;&nbsp;&nbsp; word to be searched</b><br>
&nbsp;<br>
Here is the main part set up to fit the two above possibilities:<br>
The searching part works but the indexing part when merged it
doesn't<br>
work the program jumps to the else when searching but when asked 
for<br>
indexing it doesn't execute the top section, but it compiles without
any<br>
error.&nbsp; Can anyone spot any upnormalities specialy if I got it right
the <br>
condition which evalutes&nbsp; <b>if argv[2] in [ '.txt' ] </b>which
means if the argument contains substring<b>&nbsp; '.txt'</b><br>
&nbsp;<br>
<b>here is the program</b><br>
&nbsp;<br>
def main(argv):<br>
&nbsp;&nbsp;&nbsp; if len(argv) &lt; 2:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.stderr.write(usage +
&quot;\n&quot;)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 1<br>
&nbsp;&nbsp;&nbsp; #------------------------<br>
&nbsp;&nbsp;&nbsp; #Extension = argv[2]<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; if argv[2] in ['.txt']:</blockquote><br>
Replace this with <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if argv[2].find('.txt') &gt;= 0:<br><br>
<blockquote type=cite class=cite cite>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
#print argv[2]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; indexdir = argv[1]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; files = argv[2:]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myindexer = indexer(indexdir)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for file in files:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print
&quot;indexing....&quot;, file,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
sys.stdout.flush()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
myindexer.index(file)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print
&quot;...done.&quot;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; finally:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print
&quot;committing....&quot;,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sys.stdout.flush()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myindexer.commit()<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print
&quot;....done.&quot;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0&nbsp; <br>
&nbsp;<br>
&nbsp;<br>
thanks in advance<br><br>
<br>
Do you Yahoo!?<br>
<a href="http://us.rd.yahoo.com/search/mailsig/*http://search.yahoo.com">The
New Yahoo! Search</a> - Faster. Easier. Bingo. <br>
---<br>
Incoming mail is certified Virus Free.<br>
Checked by AVG anti-virus system
(<a href="http://www.grisoft.com/" eudora="autourl">http://www.grisoft.com</a>).<br>
Version: 6.0.474 / Virus Database: 272 - Release Date:
4/18/2003</blockquote>
<x-sigsep><p></x-sigsep>
Bob Gailer<br>
bgailer@alum.rpi.edu<br>
303 442 2625<br>
</body>
</html>


--=====================_2607469==.ALT--

--=======484B4E7C=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-6D6F1DCD
Content-Disposition: inline


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.474 / Virus Database: 272 - Release Date: 4/18/2003

--=======484B4E7C=======--