I am getting some error while escaping some special characters from string using Python. The error is given below.
Error:
trans_table = string.maketrans(trans_dict)
TypeError: maketrans() takes exactly 2 arguments (1 given)
Code:
import sys
import string
if "win" in sys.platform:
special = """( ) < > * ‘ = ? ; [ ] ^ ~ ! . ” % @ / \ : + , `""".split()
else:
special = """{ } ( ) < > * ‘ = ? ; [ ] $ – # ~ ! . ” % / \ : + , `""".split()
trans_dict = {character: None for character in special}
trans_table = string.maketrans(trans_dict)
print("Lo+=r?e~~m ipsum dol;or sit!! amet, consectet..ur ad%".translate(trans_table))
Here I need to escape some special characters from the string.