這是我做的。我知道這絕對是錯誤的。我想知道如何使這個工作?謝謝!如何用下劃線替換所有空格並刪除所有括號而不使用replace()函數?
import re
def demicrosoft (fn):
"""Clean up a file name.
Remove all parentheses and replace all spaces by underscores.
Params: fn (string):
Returns: (string) clean version of fn
"""
fn = re.sub('[()]', '', fn)
for ch in ['']:
fn = fn.translate(ch, "_")
return fn
print(demicrosoft('Quercus stellata (26).jpg'))
究竟是不是工作,你有什麼期待呢? –
它說有一個TypeError:translate()只需要一個參數(給出2) – amflynn
這應該被添加到你的問題,因爲這是你真正想問的問題。另外,解釋一下你「關於1個參數,但是你給了2個」的疑惑。 –