2

I have some rather large code I've written and tested to work with the 2.7.3 version of python available in my elementary OS 0.2 system (based on Ubuntu 12.04)

My code is hosted on Github and I'd like to know if it works on newer versions of python up to 3.x.

Is there some way to do this automatically or with as little hassle as possible?

1
  • Check out 2to3 Commented Aug 14, 2014 at 22:25

1 Answer 1

1

It's unlikely that your code will work automatically unless it's some very simple script because many of the standard Python operators and methods changed. For example, the print statement becomes the print() method, and that will become a syntax error when you try to run the code.

If you're willing to take the time to set it up and install other version of python, you can use PyEnv to install multiple versions of Python to test your code with. It's very similar to Ruby's RVM if you've used that. While it's not an automated method of testing if your code will work, and it does require some setup, it is a way that you could test your code on multiple versions of Python. Once it is setup, you can continue to use it for your other Python projects as well.

In addition to PyEnv, you can take inspectorG4dget's advice from the comments and use Python's automated version 2 to version 3 code translation. Since it is unlikely that your code will work immediately in version 3 due to changing syntax of keywords and standard methods, you can use that tool to translate your code without too much effort.

Sign up to request clarification or add additional context in comments.

1 Comment

I was hesitant about doing this but it turned out to be a lot simpler than I thought and it works perfectly. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.