1、直接到項目根目錄打開終端
2、終端運行touch app.py 創(chuàng)建python 腳本文件
3、打開腳本輸入需要運行的腳本
代碼塊
#!/usr/bin/env python
import os
for dirpath, _, filenames in os.walk('.'):
for filename in filenames:
if filename.startswith('oldName'):
oldFile = os.path.join(dirpath, filename)
newFile = os.path.join(dirpath, filename.replace('oldName', 'newName', 2))
print(newFile) # 修改此處
inFile = open(oldFile)
outFile = open(newFile, 'w')
replacements = {'oldName':'newName'}
for line in inFile:
for src, target in replacements.items():
line = line.replace(src, target)
outFile.write(line)
inFile.close()
outFile.close()
os.remove(oldFile)
以上的腳本是對應(yīng)的python3的 參考鏈接
我這個只是作為備忘所以沒有寫的那么細 有興趣可以點擊鏈接去看對方的文章寫的很詳細包括如何修改項目名稱和類名前綴的 后面有時間再看看寫一個詳細的備忘