I feel like this is simple, but I just don't know enough about python to do it correctly.

I have two files:

1. File with lines listing an id number and whether that id is used. Format is 'id, isUsed'.
2. File with rules containing one rule for each id.

So what I want to do is to parse through the file with id-used pairs and then based on that information, I will find the corresponding rule in the second file and then comment or un-comment the rule based on if that rule is used.

Is there an easy way to search through the second file for the rule I am looking for instead of searching it line by line every time? Also, do I have to re-write the file every time I change the file.

Here is what I have so far I don't really know what the best way to implement modifyRulesFile():

```
def editRulesFile(pairFile, ruleFile): 
    pairFd = open(pairFile, 'r')
    ruleFd = open(ruleFile, 'rw')

    for line in pairFd.readLine():
        id,isUsed = line.split(',')

        modifyRulesFile(ruleFd, id, isUsed)

def modifyRulesFile(fd, id, isUsed):
    for line in fd.readLine():
        # Find line with id in it and add a comment or remove comment based on isUsed

```