By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,354 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

Looping issues

P: 1
I am writing a program to compare two different files.

For each line in file1 i want to compare it to all the lines in file2, then go to the next line in file1.

the code i have below is not looping back to the next line in file1, can anyone give me any suggestions to help?
Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/env python
  2.  
  3. import sys
  4. import fileinput
  5.  
  6. # Open the two files
  7. f1 = open(sys.argv[1], "r")
  8. f2 = open(sys.argv[2], "r")
  9. for line in f1:
  10.     chrR,chrStart,chrEnd,name,score,strand1,codingStart,codingEnd,itemRbg,blockCount,blockSize,BlockStart = line.strip().split()
  11.     chr = range(int(chrStart), int(chrEnd))    
  12.     lncRNA = set(chr)
  13.     for line in f2:
  14.         chrC,clustStart,clustEnd,annote,score,strand = line.strip().split()
  15.         clust = range(int(clustStart), int(clustEnd))
  16.         cluster = set(clust)
  17.         if strand1 == '-':
  18.             if chrR == chrC:
  19.                 if strand1 == strand:
  20.                     if lncRNA & cluster:
  21.                         print name, annote, 'transcript'
  22.                     else:
  23.                         continue
  24.                 continue
  25.         break
Oct 19 '11 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
Reset the file object to the beginning with f1.seek(0)
- OR -
Read the first file into a list with file method readlines() and iterate on the list.
Oct 19 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.