problem with the logic of read files

Scott David Daniels Scott.Daniels at Acm.Org
Tue Apr 12 14:12:03 EDT 2005


m_tach at yahoo.com wrote:
> #!/cbi/prg/python/current/bin/python
> # -*- coding: iso-8859-1 -*-
> import sys
> import os
> from progadn import *
> ...
> for x in extseq:
>      f = open(x, "r")
>      seq=f.read()
>      f.close()
>      s=seq
> 
> def checkDNA(seq):
>     ...
> 
> seq=checkDNA(seq)
> print seq

You terminated the loop to define checkDNA.

What you want is:
     ...
     from progadn import *
     def checkDNA(seq):
         ...

     ...
     for x in extseq:
         f = open(x, "r")
         seq=f.read()
         f.close()
         s=seq
         seq = checkDNA(seq)
         print seq

Even better might be:
     ...
     from progadn import *
     def checkDNA(seq):
         ...

     def main():
         ...
         for x in extseq:
             f = open(x, "r")
             try:
                 print checkDNA(f.read())
             finally:
                 f.close()


     if __name__ = '__main__':
         main()

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list