<pre><code>import os
import re
def rename_files():
# get the files from dir
file_list=os.listdir(r"C:\OOP\prank")
print(file_list)
saved_path=os.getcwd()
print("current working directory"+saved_path)
os.chdir(r"C:\OOP\prank")
#rename the files
for file_name in file_list:
print("old name-"+file_name)
#print("new name-"+file_name.strip("0123456789"))
os.rename(file_name,file_name.translate(None,"0123456789"))
os.chdir(saved_path)
rename_files()
</code></pre>
<p>这里显示的错误是由于翻译行…帮助我下一步做什么..我正在使用翻译从文件名中删除数字。</p>
<pre><code>Traceback (most recent call last):
File "C:\Users\vikash\AppData\Local\Programs\Python\Python35- 32\pythonprogram\secretName.py", line 17, in <module>
rename_files()
File "C:\Users\vikash\AppData\Local\Programs\Python\Python35- 32\pythonprogram\secretName.py", line 15, in rename_files
os.rename(file_name,file_name.translate(None,"0123456789"))
TypeError: translate() takes exactly one argument (2 given)
</code></pre>