1

I have to send a python script to a person but I do not know how they will run the script. Is there anything that I have to include at the top of the script to ensure that the script will run. I used TextWrangler text editor on MAC os x. Have no clue what OS they will be using or anything else for that matter. My code start with:

import itertools

....Rest of code....

Something I should add, the OS they will be using is either a distribution of linux, mac os or a newer version of windows.

bazzoli92
  • 69
  • 9
  • Are you sending this person `itertolls.py` as well? You might need to add to their `pythonpath` – inspectorG4dget Jan 29 '14 at 21:02
  • @inspectorG4dget I wasn't planning to... should I? – bazzoli92 Jan 29 '14 at 21:04
  • If that's a typo and you meant `itertools`, then no. If you actually wrote an `itertolls.py`, then yes – inspectorG4dget Jan 29 '14 at 21:05
  • 2
    Basically, tell them "run `python thescript.py` from a terminal", which works under all operating systems (even crappy Windows). – michaelmeyer Jan 29 '14 at 21:05
  • I think that was a misspelling of 'itertools'. – tdelaney Jan 29 '14 at 21:05
  • @doukremt - that only works if you've added the python directory to the system path. Most python windows installers register the .py extension. People with more exotic installations will likely also have the chops to figure out how to run it. – tdelaney Jan 29 '14 at 21:07
  • Yes sorry for the mispelling. Essentially I am sending this program for an internship. It is a software development firm so I am sure that they have python installed, etc. I just didn't want to forget to include something at the top of the file (not knowing if they will be using windows, linux or mac os) and them tell me that the script doesn't work. – bazzoli92 Jan 29 '14 at 21:15

2 Answers2

1

#!/usr/bin/env python should suffice for that.

Also, see this post: Why do people write #!/usr/bin/env python on the first line of a Python script?

Community
  • 1
  • 1
binarysubstrate
  • 2,777
  • 2
  • 18
  • 34
  • 1
    OP stated "Have no clue what OS they will be using". You assume that the environment the user calls the script with knows Shebangs. How do you know "/usr/bin/env" even exists? How do you know that "env" knows "python"? – Hyperboreus Jan 29 '14 at 21:01
  • 1
    Well, I think it's that or nothing. They don't need anything if they're going to call the script via python explicitly such as `python my_mod.py`. But this will also work on Windows perhaps depending on the distribution. I'm using it with PyCharm/Canopy for example and then also my linux machines as well without changing any code. – binarysubstrate Jan 29 '14 at 21:06
0

In Linux you can run python code through the terminal and same with Mac OS X. Also Windows Command Prompt has the same function.

All you have to do (assuming they have python installed correctly) type this into the Terminal/Command Prompt

python file.py