Haseeb Javed Haseeb Javed - 1 year ago 61
Python Question

Python - Script compatible by with which version?

Is there a way to determine what version of python is a particular script compatible with ?

I know this sounds like a stupid question but I have Python scripts from different sources. I have to manually run each script with the Python versions that I have installed on my system to check which version they are compatible with so was wondering if there is a more elegant way to do this?

Answer Source

I write a bash script to run all python script.If there is error occurs, it thinks the script is incompatible with Python2/3.


dirs=$(ls ./*.py)

for item in ${dirs}
    python2 ${item} > /dev/null 2>&1 && echo "${item} is a python2 script" && continue
    python3 ${item} > /dev/null 2>&1 && echo "${item} is a python3 script" && continue
    echo "There is an error on your ${item}"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download