Question: Behaviour of translate() method in python 3.x unlike in python 2.x?

Question

Behaviour of translate() method in python 3.x unlike in python 2.x?

Answers 0
Added at 2016-12-27 07:12
Tags
Question

Why does translate() method in python 3.x throw an TypeError if it is passed with 2 arguments unlike in python 2.x?

This is my code:

import os

def images():
file_list = os.listdir("/home/pabitra/Documents/prank/")
os.chdir("/home/pabitra/Documents/prank/")

for file_name in file_list:
    os.rename(file_name,file_name.translate(None,"0123456789"))
images()

Output:

TypeError: translate() takes exactly one argument (2 given)
Answers to

Behaviour of translate() method in python 3.x unlike in python 2.x?

Source Show
◀ Wstecz