translate() takes exactly one argument (2 given) in python error
<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>Here error is showing due to translate line ...help me what to do next ..I am using translate to remove the digit from filename.</p>

<pre><code>Traceback (most recent call last):
    File "C:\Users\vikash\AppData\Local\Programs\Python\Python35-  32\pythonprogram\secretName.py", line 17, in &lt;module&gt;
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>

<p><code>str.translate</code> requires a <code>dict</code> that maps unicode ordinals to other unicode oridinals (or <code>None</code> if you want to remove the character). You can create it like so:</p>

<pre><code>old_string = "file52.txt"
to_remove = "0123456789"
table = {ord(char): None for char in to_remove}
new_string = old_string.translate(table)
assert new_string == "file.txt"
</code></pre>

<p>However, there is simpler way of making a table though, by using the <code>str.maketrans</code> function. It can take a variety of arguments, but you want the three arg form. We ignore the first two args as they are for mapping characters to other characters. The third arg is characters you wish to remove.</p>

<pre><code>old_string = "file52.txt"
to_remove = "0123456789"
table = str.maketrans("", "", to_remove)
new_string = old_string.translate(table)
assert new_string == "file.txt"
</code></pre>

python string file