1

If I find a python script in a folder, how might the developer of this script relay to me as to which version of python the script is to be run with? I have added the first python script to a projects codebase (a system test for confirming that a bug has been fixed) and other than adding a README file, I am wondering if there is another way for pointing out that the script runs for Python 3 and not for Python 2.

My script is called bug-7.py and should be executed using "python3 bug-7.py" unless python = python3. Eventually such tests could be run using nosetest.

Baz
  • 12,713
  • 38
  • 145
  • 268
  • Please narrow this down to specifics. Have you found such a script? Does it have any comments in there or a `#!...` shebang line at the top? Anything else you can tell us about that script? – Martijn Pieters May 29 '17 at 09:10
  • If the developer did not tell you where the script was - how would you find it? The answer here is to look at the script itself - does it have any comments stating how it should be used? You'll have to look at the script itself to find any hint as to whether it was written in python 2 or 3. – Lix May 29 '17 at 09:10
  • @Martijn Pieters Added more information. – Baz May 29 '17 at 09:16
  • Just simply run it with python 2 and 3. The error-free one is your answer. – YLJ May 29 '17 at 09:21
  • @MartijnPieters I don't think this is duplicated to the one you marked. This question is about which python version should be used to run the script. The dup one is about how to specify a script to run in a specific python version. – YLJ May 29 '17 at 09:24
  • @frankyjuang: no, this is about Baz trying to figure out how to ensure that the right Python version is used for a script they wrote. Using a shebang line is the right way to communicate that. – Martijn Pieters May 29 '17 at 09:26
  • …and if there is no existing shebang and no readme and no nothing, you're left with inspecting the source for telltale signs like `print 'foo'`, and if even that is ambiguous it might be cross-compatible or it may simply be poorly documented and all you can do is try. – deceze May 29 '17 at 09:29

0 Answers0