1乘陪、直接到項(xiàng)目根目錄打開(kāi)終端
2捣炬、終端運(yùn)行touch app.py 創(chuàng)建python 腳本文件
3批幌、打開(kāi)腳本輸入需要運(yùn)行的腳本
代碼塊
#!/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)
以上的腳本是對(duì)應(yīng)的python3的 參考鏈接
我這個(gè)只是作為備忘所以沒(méi)有寫(xiě)的那么細(xì) 有興趣可以點(diǎn)擊鏈接去看對(duì)方的文章寫(xiě)的很詳細(xì)包括如何修改項(xiàng)目名稱和類名前綴的 后面有時(shí)間再看看寫(xiě)一個(gè)詳細(xì)的備忘