[Tutor] Running Existing Python

Justin Bonnell jwbonnell5 at gmail.com
Sat Feb 26 22:18:15 CET 2011


On Feb 26, 2011, at 3:29 AM, Alan Gauld wrote:

This is really helpful directions and I am trying to follow what you're saying. I think you are getting my response to another person helping me so this will basically repeat what I was saying there. I am really new to this and am trying to learn on my own so thanks for your help and patience. 

> The error says it can't find the file hello.py.
> That means its probably in some other folder 
> or you need to specify the full or relative path to the file
> This is a MacOS issue not Python, its how your MacOS 
> shell is searching for the file.
> 
> If it is in the same folder try explicitly telling MacOS:
> 
> $ python ./hello.py
> 
> Or if it is somewhere else either cd to that folder 
> or type the path:
> 
> $ python /the/full/path/to/the/dfile/hello.py

--I tried to follow this using:
/jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py
which is the correct location of the hello.py file.

> 
> There are some environment variables you can 
> set in your login script which will help MacOS 
> find the files but they depend on which shell 
> Terminal is running, tcsh or bash are the usual 
> options.
--My Terminal is running bash. 

> 
> Finally there is a trick you can use on the hello.py 
> file that means you can launch the .py file directly 
> from Finder. It's called the shebang trick by Unix 
> folks.
> 
> Basically you add a line like
> 
> #! /usr/env/python
> 
> To the very top of the file. MacOS will then use that 
> command to execute the script. If usr/env doesn't 
> work type
--So if I add that line to the file, then I use 
$ python /usr/env/python ?

> 
> $ which python
--This is the correct for my computer:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

> 
> and copy the output instead of /usr/env
> 
> 
> Alan Gauld
> Author of the Learn To Program website
> http://www.alan-g.me.uk/
> 
> 
> 
> 
> ----- Original Message ----
>> From: Justin Bonnell <jwbonnell5 at gmail.com>
>> To: Alan Gauld <alan.gauld at btinternet.com>
>> Cc: tutor at python.org
>> Sent: Saturday, 26 February, 2011 6:49:37
>> Subject: Re: [Tutor] Running Existing Python
>> 
>> Okay. When I try to run the script from the terminal, it still doesn't work.  
>> Here is a screenshot.
>> 
>> 
>> What am I doing wrong?
>> 
>> 
>> On Feb 25,  2011, at 6:46 PM, Alan Gauld wrote:
>> 
>>> 
>>> "Justin Bonnell" <jwbonnell5 at gmail.com> wrote
>>> 
>>>> Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) [GCC 4.2.1 (Apple  Inc. 
>> build 5664)] on darwin
>>>> Type "copyright", "credits" or  "license()" for more information.
>>> 
>>> The >>> prompt means  you are already inside Python.
>>> You can type Python commands at the  >>> prompt, things like
>>> 
>>>>>> print  "Hello"
>>> 
>>> But you cannot ruin a program from inside the  >>> prompt (well, you can, but 
>> its more complicated than sane people  want to bother with! :-)
>>> 
>>> You run a Python script from the OS  Terminal prompt:
>>> 
>>> $ python hello.py
>>> 
>>>> Shouldn't I be able to run hello.py from the IDLE interpreter?
>>> 
>>> You can't run it from the >>> prompt in IDLE but....
>>> What you  can do is open the file for editing and then run that file using 
>> the menu  commands, then the output will show up in the interpreter window.
>>> 
>> I  get how to do this now^^
>>> HTH,
>>> 
>>> -- 
>>> Alan  Gauld
>>> Author of the Learn to Program web site
>>> http://www.alan-g.me.uk/
>>> 
>>> 
>>> 
>>> _______________________________________________
>>> Tutor maillist   -  Tutor at python.org
>>> To unsubscribe or  change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>> 
>> 



More information about the Tutor mailing list