Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Import Error
#1
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'
Reply
#2
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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you very much for your input sir.
Reply
#4
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.)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 6,606 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  import module error tantony 5 3,434 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Cryptic Error with import statement Led_Zeppelin 2 2,528 Jan-11-2022, 01:13 PM
Last Post: Led_Zeppelin
  Install any library via pip get an error cannot import name 'SCHEME_KEYS' from 'pip. Anldra12 2 10,604 Jan-04-2022, 01:05 PM
Last Post: Anldra12
  import module with syntax error Skaperen 7 5,254 Jun-22-2021, 10:38 AM
Last Post: Skaperen
  Import Error Christian 3 3,169 Apr-17-2021, 11:27 PM
Last Post: bowlofred
  Folium import error kashif_flavio 2 3,634 Dec-07-2020, 08:58 AM
Last Post: bowlofred
  Import error Beingcode 0 2,494 Nov-20-2020, 02:57 AM
Last Post: Beingcode
Smile Import error with local file colt 1 1,917 Nov-08-2020, 07:56 AM
Last Post: Gribouillis
  switch from version 3.5.3 to 3.8.6 get import error python001 9 3,944 Oct-31-2020, 03:02 PM
Last Post: python001

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020