How do I tell what version of Python a script needs?

Viewed 65

I'm looking at some Python scripts on GitHub, but the developer doesn't specify what version (2.7 or 3.x) of Python is required.

Is there any way to tell? What type of execution errors should I look out for when a Python script fails due to version mismatch?

2 Answers

A version mismatch between Python 2 and 3 is fairly simple to find.

In python 2, print is used without brackets, for example: print "hello"

While in python 3, print is used with brackets, such as: print("hello")

Python also frequently has easy-to-read errors for differences in such where the error would end with did you mean X?

Also to input something in the command line, python 2 uses raw_input while python 3 uses input

I found this article useful. It shows almost all syntax differences between python2 and python3. by looking at it you should easily figure out. click

Some other new features like walrus operator or f-string are also for python3.

Related