Python Forum

Full Version: Import Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I wanted to import maketrans from string module but the interpreter keeps throwing Import Error for me. Please help.
Error:
Traceback (most recent call last): File "C:/Users/Test/AppData/Local/Programs/Python/Python36/maketranscode.py", line 10, in <module> from string import maketrans ImportError: cannot import name 'maketrans'
It's deprecated since python 3.1

Quote:The string.maketrans() function is deprecated and is replaced by new static methods, bytes.maketrans() and bytearray.maketrans(). This change solves the confusion around which types were supported by the string module. Now, str, bytes, and bytearray each have their own maketrans and translate methods with intermediate translation tables of the appropriate type.
Thank you very much for your input sir.
there is an equivalent in Python3
From the docs:
Quote:The string.maketrans() function is deprecated and is replaced by new static methods, bytes.maketrans() and bytearray.maketrans(). This change solves the confusion around which types were supported by the string module. Now, str, bytes, and bytearray each have their own maketrans and translate methods with intermediate translation tables of the appropriate type.

(Contributed by Georg Brandl; bpo-5675.)