[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>
<br>
first for indexing:<br>
<b>C:\TestInd>index-02.py Test Doc.txt</b><br>
<b>
|-----------------|--------|-------------|</b><br>
<b>
prog
dir file to be indexed</b><br>
<br>
Second for searching:<br>
<b>C:\TestInd>index-02.py Test word</b><br>
<b>
|-----------------|--------|-------------|</b><br>
<b>
prog
dir word to be searched</b><br>
<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. Can anyone spot any upnormalities specialy if I got it right
the <br>
condition which evalutes <b>if argv[2] in [ '.txt' ] </b>which
means if the argument contains substring<b> '.txt'</b><br>
<br>
<b>here is the program</b><br>
<br>
def main(argv):<br>
if len(argv) < 2:<br>
sys.stderr.write(usage +
"\n")<br>
return 1<br>
#------------------------<br>
#Extension = argv[2]<br>
<br>
if argv[2] in ['.txt']:</blockquote><br>
Replace this with <br>
if argv[2].find('.txt') >= 0:<br><br>
<blockquote type=cite class=cite cite>
#print argv[2]<br>
indexdir = argv[1]<br>
files = argv[2:]<br>
myindexer = indexer(indexdir)<br>
try:<br>
for file in files:<br>
print
"indexing....", file,<br>
sys.stdout.flush()<br>
myindexer.index(file)<br>
print
"...done."<br>
finally:<br>
print
"committing....",<br>
sys.stdout.flush()<br>
myindexer.commit()<br>
print
"....done."<br>
return 0 <br>
<br>
<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=======--