#!/usr/bin/python
catalog=open("physicsjournals2.txt","r")
catalogdata=catalog.readlines()
import glob
import os
import sys
directories = ['Analytica Chimica Acta' , 'Analytical and Bioanalytical Chemistry' , 'Journal of Chromatography A' , 'Sensors' , 'Talanta' , 'Carbohydrate Polymers' , 'Dyes and Pigments' , 'Food Chemistry' , 'Food Hydrocolloids' , 'Journal of Agricultural and Food Chemistry' , 'Microporous and Mesoporous Materials' , 'Dalton Transactions' , 'European Journal of Inorganic Chemistry' , 'Organometallics' , 'Angewandte Chemie - International Edition' , 'Journal of the American Chemical Society' , 'Tetrahedron - Asymmetry' , 'Biomacromolecules' , 'Journal of Organic Chemistry' , 'Organic Letters' , 'Advanced Materials' , 'Colloids and Surfaces B - Biointerfaces' , 'Journal of Physical Chemistry B' , 'Journal of Physical Chemistry C' , 'Langmuir' , 'Physical Chemistry Chemical Physics' , 'Journal of Membrane Science' , 'Macromolecular Bioscience' , 'Macromolecules' , 'Plasma Processes and Polymers']
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)
当我使用此代码获取结果时,当physicsjournals2(txt)目录具有大写和小写的行时,我得到结果。但是,我意识到这些结果是他们需要的更小的数字,所以我将目录的行改为大写(我的savedrecs txt文件中的字母都是大写的,所以它会更好地匹配),但是我得到了零结果。除了physicsjournals2之外,我所有的其他大写目录都会产生结果。 我该如何修改cataloglogournals2目录?
答案 0 :(得分:0)
您可以更改代码的这一部分:
for line in catalogdata:
rec = "SO " + line.strip().lower()
catalogRecs[rec] = True