[Tutor] Running files from command prompt

Alexander Quest redacted@example.com
Fri Jul 29 04:58:05 CEST 2011


Awesome- thanks for that Dave! The programs all work now, except that the
google exercise programs are all from Python 2.X and I'm running 3.1, so
some of them are giving me errors. Is there a way around this or do I have
to download a 2.X version so I can run these without a problem? Thanks
again.

-Alex

On Thu, Jul 28, 2011 at 7:11 PM, Dave Angel <d at davea.name> wrote:

> On 07/28/2011 09:58 PM, Alexander Quest wrote:
>
>> I downloaded the google's python exercise files from their website (
>> http://code.google.com/edu/**languages/google-python-class/**set-up.html<http://code.google.com/edu/languages/google-python-class/set-up.html>
>> ),
>> unzipped them, and placed them in C.
>> I then added the following to the PATH variable under system settings so
>> that I could type "python" in command prompt and have Windows start the
>> interpreter: C:\Python31;C:\Python31\Tools\**Scripts
>>
>> When I type in "python" in the command prompt, the interpreter opens, but
>> when I try to open one of the programs from the Google exercise files
>> (hello.py), I get the following error:
>> Traceback<most recent call last>:
>>    File "<stdin>", line 1, in<module>
>> NameError: name 'hello' is not defined
>>
>>
> When you're running the python interpreter, you can't just type the name of
> your script.  You need to import it
>     import hello
>
> However, first it needs to be in the python's module search path.  Easiest
> way is to make
>  it your current directory.
>
> So, from a command prompt:
>
> cd C:\google-python-exercises
>
> python
> XXXX starting Python version ....
>
> >>>>import hello
>
>
>
>  Or, if I just type in "python hello.py" first in the command prompt (as
>> opposed to typing in python, hitting enter, and THEN typing in hello.py,
>> as
>> above), I get the following error:
>>
>>
>> python: can't open file 'hello.py': [Errno 2] No such file or directory.
>>
>> So I guess my question is how do I run .py files from the command prompt
>> now
>> that I seem to have gotten Windows to recognize and open the interpreter
>> when I type in "python"? Thanks for any help.
>>
>>  Similarly, before running python, change to the directory you want the
> script to run in.
> Normally, you'd do:
>
> cd c:\google-python-exercises
> python hello.py
>
>
>
>  -Alex
>>
>> P.S. Just as an aside, when I open up the command prompt, the initial
>> directory is C:\Users\Alexander, but my google exercises are in
>> C:\google-python-exercises and python itself is in C:\Python31. I don't
>> know
>> if this makes a difference or not.
>>
>>
>
> --
>
> DaveA
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110728/26270424/attachment-0001.html>


More information about the Tutor mailing list
l>