32 lines
979 B
Python
32 lines
979 B
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
def remove_hash_from_specialties():
|
|||
|
|
"""删除导师专长标签中的#号"""
|
|||
|
|
|
|||
|
|
# 读取mockData.js文件
|
|||
|
|
with open('src/data/mockData.js', 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 使用正则表达式替换specialties数组中的"# "
|
|||
|
|
# 匹配模式:specialties: [...] 中的所有 "# xxx"
|
|||
|
|
def replace_hash(match):
|
|||
|
|
specialties_str = match.group(0)
|
|||
|
|
# 替换所有的 "# " 为 ""
|
|||
|
|
specialties_str = specialties_str.replace('"# ', '"')
|
|||
|
|
return specialties_str
|
|||
|
|
|
|||
|
|
# 匹配specialties数组
|
|||
|
|
pattern = r'specialties:\s*\[[^\]]+\]'
|
|||
|
|
new_content = re.sub(pattern, replace_hash, content)
|
|||
|
|
|
|||
|
|
# 写回文件
|
|||
|
|
with open('src/data/mockData.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(new_content)
|
|||
|
|
|
|||
|
|
print("成功删除所有导师专长标签中的#号")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
remove_hash_from_specialties()
|