我正在使用 Python 3,我想将我的文件名翻译为没有数字。翻译功能似乎在 Python 3 中不起作用。如何将文件名翻译为没有数字?
这是不起作用的代码块:
file_name = "123hello.jpg"
file_name.translate(None, "0123456789")
谢谢
最佳答案
str.translate
还在,只是界面变了一点:
>>> table = str.maketrans(dict.fromkeys('0123456789'))
>>> '123hello.jpg'.translate(table)
'hello.jpg'
关于python - Python 3 中的翻译函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41708770/