Last active
December 25, 2018 07:37
-
-
Save lichunzhu/be7ff26110b5e4806c5170e34504b4be to your computer and use it in GitHub Desktop.
改变IEEE RIS引用格式使其在endnote里显示date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import os | |
path = "E:/pythoncode/ris_files" # 文件夹目录 | |
files = os.listdir(path) # 得到文件夹下的所有文件名称 | |
def is_character(x): | |
return ord('a') <= ord(x) <= ord('z') or ord('A') <= ord(x) <= ord('Z') | |
for risFile in files: # 遍历文件夹 | |
if not os.path.isdir(path + "/" + risFile): # 判断是否是文件夹,不是文件夹才打开 | |
f = open(path + "/" + risFile) # 打开文件 | |
risNewFile = "new/" + risFile | |
new_f = open(path + "/" + risNewFile, "w") | |
iter_f = iter(f) # 创建迭代器 | |
for line in iter_f: # 遍历文件,一行行遍历,读取文本 | |
if line[0:2] == "Y1": | |
pos = line.find("- ") | |
pos += 2 | |
new_line = "DA" + line[2:pos] | |
for i in range(pos, len(line)): | |
if line[i] == '.' or is_character(line[i]): | |
new_line += line[i] | |
print "in file " + risFile + ":" | |
print line + " has been changed to " + new_line | |
line = new_line + '\n' | |
new_f.write(line) | |
f.close() | |
new_f.close() | |
print "All files have been changed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment