使用时
first = raw_input('mol bio results + count')
f1 = open(first,'r')
f1data = f1.readlines()
second = raw_input('physics journal list')
f2 = open(second,'r')
f2data = f2.readlines()
total = 0
for line1 in f1data:
i = 0
for line2 in f2data:
if line1 in line2:
i+=1
total+=1
print line1 + str(i) + "\n"
print total
它只会在屏幕上写下第一个文件的名称(“mol bio results + count”),而它永远不会加载。 我的代码错了吗?这两个文件都显示在它显示我正在使用的文件夹的位置。 感谢。
答案 0 :(得分:0)
我已在我的系统上尝试过您的代码。 raw_input()完美无缺。确保您的代码符合您使用的python版本。或者也许你的python坏了。可能是因为有些东西阻止了python访问你的文件。在这种情况下,请检查您是否有足够的权限来读取该文件。
答案 1 :(得分:0)
raw_input将字符串打印为提示并等待输入和输入。
我不知道你的python有多近,但我选择的语法将为你处理文件(除其他外)
我还冒昧地重新格式化并重命名了一些变量以保持清晰
print("Please enter the file name for mol bio results + count")
first = raw_input('(Type it here and press enter) : ')
print("Please enter the file name for physics journal list")
second = raw_input(': ')
with open(first, 'r') as f1:
f1data = f1.readlines()
with open(second, 'r') as f2:
f2data = f2.readlines()
total = 0
for f1line in f1data:
i = 0
# print(len(f1line))
for f2line in f2data:
# print(len(f2line))
if f1line.rstrip() in f2line:
i += 1
total += 1
print f1line + ':' + str(i) + "\n"
print total