今天我再跑一个开源的项目,人家给我了一个环境列表,长下面这个样子:
allennlp 2.6.0
anykeystore 0.2
argon2-cffi 20.1.0
astor 0.8.1
astunparse 1.6.3
async-generator 1.10
async-timeout 3.0.1
attrs 19.3.0
backcall 0.1.0
backports-csv 1.0.7
我想要把他变成下面这个样子,然后放到虚拟机中去批量下载这些包:
_libgcc_mutex==0.1
absl-py==0.13.0
aiohttp==3.7.4.post0
allennlp==2.6.0
anykeystore==0.2
argon2-cffi==20.1.0
astor==0.8.1
astunparse==1.6.3
async-generator==1.10
详情见代码
# 逐行读取txt文件
if __name__=='__main__':
with open('requirement.txt','r',encoding='utf-8')as f:
content=f.readlines()
package_names=[]
for line in content:
txt=line.strip().split(" ")
package_name=txt[0]+"=="+txt[-1]
package_names.append(package_name)
print(package_name)
# 逐行写入txt文件
with open('requirements.txt','w',encoding='utf-8')as f:
for i in package_names:
f.write(i+'\n')