0

I want to be able to check if a function is compatible with Python 3 from the python code (not through a terminal). A string containing the function would be passed into the check.

As far as I know I can only use 2to3 in the terminal to convert Python documents from Python 2 to Python 3. Is there a way I can use this or something else to first check the code in a string and, if it needs to be converted to Python 3, to write the necessary changes back to the string?

How I would like it to work:

def checkCodeCompatibility(functionInString):
    if codeIncompatibleWithPython3:
         return convertCodeToPython3(functionInString)
  • Given that both cases result in code that is compatible with Python 3, what's the reason for checking and not just running the compatibility tool regardless? – Kemp Jun 03 '21 at 11:53
  • 1
    *As far as I know I can only use 2to3 in the terminal:* not true. Look at the code and you will see what classes to use from a program. – BoarGules Jun 03 '21 at 11:55
  • @Kemp Running the compatibility tool on code that is already compatible can cause incorrect changes in some cases, so it's preferable to not have to run the tool unnecessarily. – ImCoding2907 Jun 03 '21 at 11:57

0 Answers0