0

Hello there i need some help for a little, i working on python version 3/2, i wanna create a system detection on python script and how can i solve the problem like this:

try:
    import platform
    
    python_sysvers = platform.python_version()
    if (self.linux_prompt()):
        if int(python_sysvers[0]) == True:
            command = input("")
    else:
            if (self.linux_prompt()):
                if int(python_sysvers[0]) == True:
                    return input(self.getlinux_prompt())

        while True:
            if command == 'terminate':
                if 'terminate' in command:
                    self.quit = True
                    return

    self.sock.send(command)

ok from the code i wrote above i aim to call "raw_input()" if it is python version 2 but if it is in higher version the function refer to "input()" function then how to make it when we run the code it either uses python version 2 or version 3 the code can run compatible and if I run the code with python version 3 it doesn't get transferred to python version 2 code, ... the above code is intended to be easier to maintain thank you ^^

solve how to calling python 2 codes on python 3

  • 1
    This link may be useful: https://stackoverflow.com/questions/9079036/how-do-i-detect-the-python-version-at-runtime – jrd1 Apr 06 '23 at 21:08
  • I think you've taken on a hopeless task, and your expectation that it will be easier to maintain is wrong. There are syntax differences in 2.x and 3.x, like the `print` statement, so you can't realistically load the same scripts into both. If you really need to support the obsolete version, you should just have two different versions of your library, and have users install the appropriate one for their environment. – Barmar Apr 06 '23 at 21:28
  • Do you really need to support Python 2? It's been dead for over 3 years and this was announced 10 years before. – Matthias Apr 06 '23 at 21:48
  • @Barmar ohh thank you sir i got the point – doomster_legion Apr 07 '23 at 05:29

0 Answers0