running python 2 vs 3

John Gordon gordon at
Thu Mar 20 20:07:39 CET 2014

In <bp0lohF7aqdU3 at> notbob <notbob at> writes:

> On 2014-03-20, Zachary Ware <zachary.ware+pylist at> wrote:

> > If you're specifying the interpreter in your command (by calling
> > "python <scriptname>.py", etc), the shebang won't mean anything
> > anyway.

> DOH!  

> I was following you, fine, until that last sentence.  Then how should
> I invoke the scripts? your example is exactly how I've been
> doing it with 2.7, as per Learn Python the Hard Way.  Simply
> ./<scriptname>.py from the appropriate directory (assuming I keep both
> vers in separate dirs)?

There are two ways (at least!) to run a python script:

1. Execute the python interpreter manually, supplying the python script name
   as an arugment, like so:


This lets you choose on-the-fly which version of python is being used to
interpret the script.

2. Execute the python script directly by just typing its name, like so:

   Depending on your operating system, this may require:
     a. Permissions on the script file be set to allow execution; 
     b. A 'shebang' entry as the first line in the file which specifies the
        program that shall be executed;

John Gordon         Imagine what it must be like for a real medical doctor to
gordon at    watch 'House', or a real serial killer to watch 'Dexter'.

More information about the Python-list mailing list