Mina
Mina

Reputation: 159

When matching, code yields inadequate results python

this is my code, i use it to match the citations in a savedrecs file to the citations in a catalog from a website. The resulting numbers came too small so I think there is a problem with the code.

#!/usr/bin/python

catalog=open("chemjournals1.txt","r")
catalogdata=catalog.readlines()

import glob
import os
import sys

directories = ['Biomaterials' , 'Biophysical Journal' , 'Journal of Biological Chemistry' , 'Molecular and Cellular Biology' , 'Molecular Aspects of Medicine' , 'PLoS Computational Biology']

 catalogRecs = {}

for line in catalogdata:
    rec = "SO " + line.strip()
    catalogRecs[rec] = True

for folder in directories:
    savedrecfilenames = glob.glob(os.path.join(folder, "savedrecs (*).txt     journals.txt"))
    #print savedrecfilenames
    for savedrecfilename in savedrecfilenames:
        i = 0
        savedrecfile=open(savedrecfilename,"r")
        fdata=savedrecfile.readlines()
        for line in fdata:
            name = line.strip()
            #print name
            if catalogRecs.has_key(name):
                i+=1
        print savedrecfilename + " cited " + str(i) + " sources."
        ## veya sadece sayi outputlamak istersen
        print str(i)

Upvotes: 2

Views: 57

Answers (1)

mvelay
mvelay

Reputation: 1520

To me, there is an issue here:savedrecfilenames = glob.glob(os.path.join(folder, "savedrecs (*).txt journals.txt"))

What are you trying to do ?

https://docs.python.org/2/library/os.path.html#os.path.join

savedrecfilenames = [glob.glob(os.path.join(folder, pattern)) for pattern in ["savedrecs, (*).txt, journals.txt"]] could do the job

Upvotes: 2

Related Questions