[Tutor] Running Existing Python

2011-02-25 Thread Justin Bonnell
I downloaded Python 2.7.1. I think this is a pretty basic question.
When I try to run the existing python files on the computer (hello.py), I 
receive a syntax error. 

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.
>>> python hello.py
SyntaxError: invalid syntax

I am running Mac OS X version 10.6.6.
Shouldn't I be able to run hello.py from the IDLE interpreter?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running Existing Python

2011-02-26 Thread Justin Bonnell
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"  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@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running Existing Python

2011-02-26 Thread Justin Bonnell

On Feb 26, 2011, at 4:49 AM, Dave Angel wrote:

> On 01/-10/-28163 02:59 PM, Justin Bonnell wrote:
>> 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?
>> 
> 1) You're top-posting.  Put your responses after the quote you're responding 
> to.
--Okay. I'm pretty new to this so most of my responses were just general 
questions rather than specific responses.
> 
> 2) You're trying to include graphical images in a text-based newsgroup.  Just 
> use copy/paste, and include it in your message.
--Got it. I will do that from now on. 

> 
> 3) You don't tell us where the hello.py file actually is.  Presumably it's 
> not in the current directory when you run that.  Two cures for that:  either 
> specify its real location,
> python   ~/mysources/hello.py

--This is the location of the file:

/jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py

but it still says it cannot find the directory when I try to run it or cd to 
it. Is there any way that I can tell which directory the shell is currently 
working from?

> or cd to the proper directory.  The latter is usually easier, but it depends 
> where other files your script are located.
> 
> DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running Existing Python

2011-02-26 Thread Justin Bonnell

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 
>> To: Alan Gauld 
>> Cc: tutor@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"  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@python.org
>>> To unsubscribe or  change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>> 
>> 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running Existing Python

2011-02-26 Thread Justin Bonnell

On Feb 26, 2011, at 3:18 PM, Corey Richardson wrote:

> On 02/26/2011 04:10 PM, Justin Bonnell wrote:
> 
>> --This is the location of the file:
>> 
>>  /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py
>> 
>> but it still says it cannot find the directory when I try to run it or cd to 
>> it. Is there any way that I can tell which directory the shell is currently 
>> working from?
> 
> At the terminal, the command "pwd" , print working directory, should do
> the trick.
> 
> If you cannot cd to the directory, that's generally a pretty big hint
> that the directory doesn't exist ;-)
> 
> But yet you can see it in your file browser? That's most curious.

--My current working directory is not what I have been trying to cd to, so I'm 
assuming that I am using the cd command wrong. 

I have tried:

$ cd /jwbonnell/bin/Python\2.7/Extras/Demo/tkinter/guido
$ cd /jwbonnell/bin/Python\2.7/Extras/Demo/tkinter/guido/hello.py
$ cd /jwbonnell/bin/Python 2.7/Extras/Demo/tkinter/guido/hello.py

> 
> -- 
> Corey Richardson
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] textbook question

2011-02-27 Thread Justin Bonnell
In trying to learn Python, I'm reading through How to Think Like a Computer 
Scientist. I'm just on the third chapter but I'm getting stuck on this question:

Fill in the body of the function definition for cat_n_times so that it will 
print the string, s, n times:

def cat_n_times(s, n):

Save this function in a script named import_test.py. Now at a unix prompt, make 
sure you are in the same directory where the import_test.py is located ( ls 
should show import_test.py). Start a Python shell and try the following:

>>> from import_test import *
>>> cat_n_times('Spam', 7)
SpamSpamSpamSpamSpamSpamSpam
If all is well, your session should work the same as this one. Experiment with 
other calls to cat_n_times until you feel comfortable with how it works.

I'm thinking it should be pretty easy but, again, I'm a beginner.
I copied the whole question but basically I just need some help with what the 
script should look like, that'd be great.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor