New guy question 
Author Message
 New guy question

I have a small script I entered from a python book that works when I run it
using F5.
However, when I go to the console and enter python alook.py, I get an error
message:

Quote:
>>> python alook.py

SyntaxError: invalid syntax

I am too new to this to know why.

Glen



Thu, 27 Nov 2003 07:28:51 GMT  
 New guy question

Quote:
> However, when I go to the console and enter python alook.py, I get an error
> message:

> >>> python alook.py
> SyntaxError: invalid syntax

Based on the '>>>' prefix It looks like you're entering this into the
python interpreter.  In that context, to get the same behaviour, you
would probably want to do something like "execfile('alook.py')"  Try
running "python alook.py" from the shell/dos command prompt, instead.
It might be helpful to work through a tutorial.  The one at
www.python.org/doc/tut is pretty good, imo.

Alex.



Thu, 27 Nov 2003 08:03:23 GMT  
 New guy question

Quote:
> Based on the '>>>' prefix It looks like you're entering this into the
> python interpreter.  In that context, to get the same behaviour, you
> would probably want to do something like "execfile('alook.py')"  Try
> running "python alook.py" from the shell/dos command prompt, instead.
> It might be helpful to work through a tutorial.  The one at
> www.python.org/doc/tut is pretty good, imo.

> Alex.

Actually, I am working thru a tutorial right now.  I don't recall it saying
anything about the differences between the DOS window and the IDLE window.
In any case, I went to the DOS window and this is what I get:

Quote:
>>> python alook.py

   File "<stdin>", line 1
       python alook.py
                        ^
SyntaxError:  invalid syntax

Glen



Thu, 27 Nov 2003 10:59:17 GMT  
 New guy question
| I have a small script I entered from a Python book that works when I run it
| using F5.
| However, when I go to the console and enter python alook.py, I get an error
| message:
|
| >>> python alook.py
| SyntaxError: invalid syntax
|
| I am too new to this to know why.

As Alex indicated, it is not a problem with understanding python.  I
have seen that "new" Wintel-PC users often don't know what a shell is.
A "shell" is a prompt provided by the OS to enter commands.  On
"Wintel" boxes it used to be called DOS.  Now it is either called
"MS-DOS Prompt" or "Command Prompt" and can be found under the Start
menu.  On a Unix system their are many different shells, and the shell
is the first thing you will learn.  A shell is where you would type
things like "cd" "copy" "del", etc.  There you can type "python
alook.py" (assuming alook.py is in the current directory) to run the
program.  The prompt (for a DOS shell) is "C:\>" or something similar.

You have the "Python Interactive Interpreter" there, indicated by the
">>>" prompt.  In this shell-like window you can enter python
statements only.  No OS commands are allowed because they aren't
python code.

If you have any more questions re shells and DOS/Windows feel free to
ask.  You may also be interested in the "Tutor" list,

HTH,
-D



Thu, 27 Nov 2003 10:03:37 GMT  
 New guy question

wrote in comp.lang.python in article

:> Based on the '>>>' prefix It looks like you're entering this into the
:> python interpreter.  In that context, to get the same behaviour, you
:> would probably want to do something like "execfile('alook.py')"  Try
:> running "python alook.py" from the shell/dos command prompt, instead.
:> It might be helpful to work through a tutorial.  The one at
:> www.python.org/doc/tut is pretty good, imo.
:>
:> Alex.
:
:Actually, I am working thru a tutorial right now.  I don't recall it saying
:anything about the differences between the DOS window and the IDLE window.
:In any case, I went to the DOS window and this is what I get:
:
:>>> python alook.py
:   File "<stdin>", line 1
:       python alook.py
:                        ^
:SyntaxError:  invalid syntax
:>>>
:
:Glen

You are not in a DOS window if you have the

which is what D-man was trying to tell you. If you went to the Start
Menu, and then Programs, and then Python, and then DOS Window, that puts
you in the Python Interpreter within a DOS Window.

Do this:
Go to the Start Menu
Go to Programs
Go to MS-DOS prompt

This will open a small window with a mostly black background. You should
not see the

Instead, you will see something like

C:\Windows\Programs>

or something like that

at the prompt above, type

python alook.py

and then see what happens.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



Thu, 27 Nov 2003 11:12:39 GMT  
 New guy question

..of course you can also run your program from the >>> prompt:
( in addition to Alex's suggestion:  >>>execfile('alook.py')  )

Quote:
>>> import alook

..will effectively 'run' your program.
( actually it loads it into the current namespace, -- more or less the same
thing)
( note that you leave of the .py extension )
The file alook.py must be on the sys.path -- another issue )

..but the next time you will have to type:

Quote:
>>> reload(alook)

.. because Python will not import the same thing twice,
even if the file has changed.


Quote:

> | I have a small script I entered from a Python book that works when I run
it
> | using F5.
> | However, when I go to the console and enter python alook.py, I get an
error
> | message:
> |
> | >>> python alook.py
> | SyntaxError: invalid syntax
> |
> | I am too new to this to know why.

> As Alex indicated, it is not a problem with understanding python.  I
> have seen that "new" Wintel-PC users often don't know what a shell is.
> A "shell" is a prompt provided by the OS to enter commands.  On
> "Wintel" boxes it used to be called DOS.  Now it is either called
> "MS-DOS Prompt" or "Command Prompt" and can be found under the Start
> menu.  On a Unix system their are many different shells, and the shell
> is the first thing you will learn.  A shell is where you would type
> things like "cd" "copy" "del", etc.  There you can type "python
> alook.py" (assuming alook.py is in the current directory) to run the
> program.  The prompt (for a DOS shell) is "C:\>" or something similar.

> You have the "Python Interactive Interpreter" there, indicated by the
> ">>>" prompt.  In this shell-like window you can enter python
> statements only.  No OS commands are allowed because they aren't
> python code.

> If you have any more questions re shells and DOS/Windows feel free to
> ask.  You may also be interested in the "Tutor" list,

> HTH,
> -D



Thu, 27 Nov 2003 13:49:44 GMT  
 New guy question

Quote:

> ..of course you can also run your program from the >>> prompt:
> ( in addition to Alex's suggestion:  >>>execfile('alook.py')  )

> >>> import alook

> ..will effectively 'run' your program.
> ( actually it loads it into the current namespace, -- more or less the
same
> thing)
> ( note that you leave of the .py extension )
> The file alook.py must be on the sys.path -- another issue )

Also, if code in alook.py has a test such as:
    if __name__=='__main__':
        ...
it will work differently under import as opposed to execfile (or being
run at a shell prompt).  This is very handy, and highly idiomatic in
Python, too -- it lets you define an alook.py that defines functions,
classes &c which other modules can use, AND also may be run as
a stand-alone 'program' (but not with import:-).

Alex



Thu, 27 Nov 2003 15:33:25 GMT  
 New guy question
OK...I went back to the beginning and discovered that the author of the
tutorial showed me three windows.
One with a black background that he described as the Python prompt (>>>)
(title is Python)
One with a white background that he described as IDLE - also with a Python
prompt (title is Python Shell)
One with a black background that he described as the "command" window that
in fact is the DOS window (title MS DOS Prompt)

I went to the MS DOS Prompt ("Command") and typed in python alook.py and got
an error message:  Bad command or file name.


Quote:
> I have a small script I entered from a Python book that works when I run
it
> using F5.
> However, when I go to the console and enter python alook.py, I get an
error
> message:  >
> >>> python alook.py
> SyntaxError: invalid syntax

> I am too new to this to know why.

> Glen



Thu, 27 Nov 2003 21:04:35 GMT  
 New guy question
I forgot to ask - what is the purpose of the Python window and the Python
Shell window?

Can I NOT run a series of scripts from these windows?  Must I go to the DOS
window to check my program?

Glen


Quote:
> I have a small script I entered from a Python book that works when I run
it
> using F5.
> However, when I go to the console and enter python alook.py, I get an
error
> message:

> >>> python alook.py
> SyntaxError: invalid syntax

> I am too new to this to know why.

> Glen



Thu, 27 Nov 2003 21:09:03 GMT  
 New guy question

wrote in comp.lang.python in article

:OK...I went back to the beginning and discovered that the author of the
:tutorial showed me three windows.
:One with a black background that he described as the Python prompt (>>>)
:(title is Python)
:One with a white background that he described as IDLE - also with a Python
:prompt (title is Python Shell)
:One with a black background that he described as the "command" window that
:in fact is the DOS window (title MS DOS Prompt)
:
:I went to the MS DOS Prompt ("Command") and typed in python alook.py and got
:an error message:  Bad command or file name.

This sounds like Python is not in the PATH for your computer. (When it
says, "Bad command or file name" it is basically telling you that it
doesn't understand how to execute the command that you gave it. The
reason it doesn't understand, is because it doesn't know where your
"python" executable is.)

You can fix it this way:

Go to the Start Menu. Click on "Run".
Under "Run" a little dialog box should pop up with a little box to type
in the name of something.
Type in
msconfig
and click on "OK".

When it pops up a window, choose the tab that says "Autoexec.bat".
Somewhere in there you need to add a statement. So pick the button that
says "New".

Type
SET PATH = C:\Python\Python20;%PATH%

except that instead of C:\Python\Python20
you need to put the path to Python on YOUR COMPUTER.

I would also use the Move Down button and put this lower in the list of
commands to your Autoexec.bat file.

Reboot your machine and then try bringing up a DOS window and typing
python alook.py
at the DOS prompt. Hopefully it should work now.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/


:> I have a small script I entered from a Python book that works when I run
:it
:> using F5.
:> However, when I go to the console and enter python alook.py, I get an
:error
:> message:  >
:> >>> python alook.py
:> SyntaxError: invalid syntax
:>
:> I am too new to this to know why.
:>
:> Glen
:>
:>
:



Thu, 27 Nov 2003 22:24:50 GMT  
 New guy question
Well, try this then:

Get into Idle - from the File dropdown menu select new window.
In the new window type in: print "Hello World!
In the new window, from the File dropdown menu select Save As then enter the
file name as test.py.
With the new window (now renamed test.py) selected, hit the F5 key - this
runs the script and in the Python Shell window you should see the words:
Hello World!

You'll still need to learn how to either navigate to python.exe's home
directory, add to your environment's path, or otherwise register .py
scripts, but at least you'll be able to see python do something and save
your experiments.

HTH,

--

Emile van Sebille

---------

Quote:
> I forgot to ask - what is the purpose of the Python window and the Python
> Shell window?

> Can I NOT run a series of scripts from these windows?  Must I go to the
DOS
> window to check my program?

> Glen



> > I have a small script I entered from a Python book that works when I run
> it
> > using F5.
> > However, when I go to the console and enter python alook.py, I get an
> error
> > message:

> > >>> python alook.py
> > SyntaxError: invalid syntax

> > I am too new to this to know why.

> > Glen



Thu, 27 Nov 2003 22:20:52 GMT  
 New guy question

wrote in comp.lang.python in article

:I forgot to ask - what is the purpose of the Python window and the Python
:Shell window?
:
:Can I NOT run a series of scripts from these windows?  Must I go to the DOS
:window to check my program?
:
:Glen

You do not have to check your scripts from the DOS prompt. You can run
them from inside of IDLE. What you should do is this:

In IDLE go to the File Menu and choose "Open..."
This should pop up a window where you can look on your computer for the
file alook.py.

When you select that file, it should open in a new window. It will show
the code for your file alook.py. In this new window (the title should
say alook.py-path/to/alook.py), go to the Edit Menu and choose "Run
Script". The output will appear in IDLE's Python Shell window.

Hope this helps,

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/


:> I have a small script I entered from a Python book that works when I run
:it
:> using F5.
:> However, when I go to the console and enter python alook.py, I get an
:error
:> message:
:>
:> >>> python alook.py
:> SyntaxError: invalid syntax
:>
:> I am too new to this to know why.
:>
:> Glen
:>
:>
:



Thu, 27 Nov 2003 22:28:39 GMT  
 New guy question

in comp.lang.python in article

:Reboot your machine and then try bringing up a DOS window and typing
:python alook.py
:at the DOS prompt. Hopefully it should work now.

I just thought of something. Maybe Python is already in the PATH in your
Autoexec.bat file, and the reason you are getting
"Bad command or file name"
is because you are not giving the full path to alook.py

Maybe you don't need to do all the stuff I suggested with the msconfig
and Autoexec.bat file.

How about trying this instead:
If alook.py is really c:\Python\Python20\alook.py
(or whatever the full path is to that file on your machine)

Try typing this in a DOS prompt window:
python c:\Python\Python20\alook.py

(Of course, modify the above to give the actual path to alook.py)

Does this work for you???

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/



Thu, 27 Nov 2003 23:01:09 GMT  
 New guy question

    ...

Quote:
> I went to the MS DOS Prompt ("Command") and typed in python alook.py and
got
> an error message:  Bad command or file name.

Then the directory with Python.Exe (e.g. C:\Python21 in a typical
Python 2.1 installation) is not in your PATH.  You can remedy this
differently in different versions of Windows.  Easiest in NT/2000
(and I assume XP): Start/Settings/Control Panel/System/
Environment -- you'll find a PATH among the user and/or system
environment settings, a list of directories separated by semicolons
(;), and you can add c:\Python21 to it.  Easiest in 95/98/ME: edit
c:\Autoexec.bat.  It probably already exists and already includes
a PATH statement of a form such as
    PATH c:\foo;d:\bar;%PATH%
edit it to
    PATH c:\Python21;c:\foo;d:\bar;%PATH%
or if no such statements were there, create one
    PATH c:\Python21;%PATH%

Rebooting after such setting-change is not strictly necessary for
NT (it is for 95) but is advisable anyway.

There are alternatives (that involve editing the Windows registry,
for example) but I think they're less simple.

Alex



Thu, 27 Nov 2003 22:57:33 GMT  
 New guy question


Quote:
> OK...I went back to the beginning and discovered that the author of the
> tutorial showed me three windows.
> One with a black background that he described as the Python prompt (>>>)
> (title is Python)
> One with a white background that he described as IDLE - also with a Python
> prompt (title is Python Shell)
> One with a black background that he described as the "command" window that
> in fact is the DOS window (title MS DOS Prompt)

> I went to the MS DOS Prompt ("Command") and typed in python alook.py and
got
> an error message:  Bad command or file name.




This means that Python is not in your path - in other words, Windows can't
find out where the program is located. The advice you've gotten up to now is
pretty good, but I don't recommend changing Autoexec.bat unless you know
what you're doing. It's too easy to drop a semicolon and{*filter*}up your
system
to where it won't boot. In addition, I'm told that Autoexec.bat is ignored
on
Windows ME (I'm not certain about that, I've never upgraded.)

What I'm doing looks a bit more complicated, but it works (something that
 is always recommended.)

1. Copy an MS-Dos icon into the directory with your test programs.
2. Create a new .txt file there.
3. Put one line in it:
path=%path%;c:\python21\bin
  spelled exactly like that, no spaces. If your Python21 directory is
somewhere
else, you'll have to change it.
4. change the file type from .txt to .bat
5. Right-click on the Dos icon and select Properties. Make certain it does
not
specify "close on exit." Also make certain that the working directory box
specifies the directory with your Python program.
6. When you want to run a command line, double click on this command icon.
It should show you the directory you're working in.
7. type <command>.bat (whatever you named your command file.) That
should show you the new path. Even if you make a mistake, it won't affect
anything else. The change is completely local to the dos box.
8. type python alook.py

That should get you into your program properly.

I grant you, this looks messy, and I wish there was an easier way, but this
works.

John Roth



Fri, 28 Nov 2003 06:10:55 GMT  
 
 [ 20 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Obligatory New Guy Question

2. Obligatory New Guy Question

3. New guy question

4. New Guy question

5. Interesting little question from a new guy

6. New guy has simple question

7. New guy, dumb question...

8. New Guy needs help!

9. new guy OK

10. New Guy

11. new guy

12. The New Guy...

 

 
Powered by phpBB® Forum Software