Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   Command Line (http://www.programmingforums.org/showthread.php?t=386)

Insomniac Aug 20th, 2004 12:52 AM

Still very new to this.

Ive gone through the tutorials many times and Im simply convinced there's something wrong with my version.

Right now, and usually when Im writing, I have 3 tabs. The command line, the shell, and the editor.

Ok, fine. I write out a sample program in the editor and go to run it, it asks me to save which is cool.

Then the program runs in the shell nicely.

The problem lies when I try to run the program on the command line with 'python (name of program)'. I always get a syntax error. I followed the writing and saving or saving and finding the programs directions to the T, but I can't seem to run a program using the 'python' command or I can't at all run a program on the command line. Whats up?

Further, when Python asks me to save a program which Ive just written before running it, I do and I give it a name... but I dont see the other programs in there at all. Even when I use, 'start, run, browse, foldername' it's not there. Where did they go??

The only way I can open a saved program is by using the editor and clicking File, Open... that's it!

There's gotta be other ways, no?

thechristelegacy Aug 20th, 2004 1:01 AM

Make sure you've saving the files as .py and when you run them from a command line don't forget to add the .py extension. The version shouldn't make a differnce.

Also, if you could give me the exact error you recieve that would be a great help.

Make sure that CMD.exe is in the right directoy. For example when I open CMD it starts out in C:\Documents and Settings\FPHA and if I want to run a python script that I saved in C:\Python as script.py I have to type the following in.



cd C:\Python
python script.py


Hope that helps out!

:-D

Insomniac Aug 20th, 2004 1:39 AM

This is messed up.



I did the simple program, Hello. - one line, on the editor. When I went to run it, Shell asked to save it, so I saved it hello.py, then shell runs it.

I try it at the Command line. Nothing.

I go back into the shell, click File, click open, the window opens and my file is not there.

Im lost.

As for the other things.... Python23 looks like this: C:\Python23 and thats it.

Error message after typing : python hello.py

File "<stdin>", line 1
python hello.py
^ - (directly under the o)
SyntaxError: invalid syntax

thechristelegacy Aug 20th, 2004 1:47 AM

Quote:

Originally posted by Insomniac@Aug 20 2004, 02:39 AM
Error message after typing : python hello.py

File "<stdin>", line 1
python hello.py
^ - (directly under the o)
SyntaxError: invalid syntax

That's the python interpreter, not you're command window. To run the program you need to use the command window.

To open a command window, click start, RUN and type CMD.exe

When that window comes change your directory to whevrever you save your python files (default is the python directory).

To change your directoy from inside the command window type


cd C:\Python23 (or whatever directory your script might be saved in)

and then type

python script.py


Make sure to try that from inside the command window and not the Python interpreter.

Insomniac Aug 20th, 2004 2:07 AM

OMG, lol.

Thank you legacy.

Why do we use the CMD.exe ? That's simliar or it IS Dos, no? Dangit I read nowhere on those tutorials that says to open this specific line.

Where that error was, you said intepreter... the tutorial says 'if you open the file and its lists 'Python, version, date, system' at the top and then copyright stuff, and has NO drop down menus, and also has the >>> then you're at the command line.'

Their tutorial needs to say exactly what you said, 'start, run, cmd.exe'. - would've been a time saver. Sheesh.

Ok, now Im able to pull up those .py files correctly.

So that I have this correctly, there exists the editor for writing them, the shell for running them, command line for executing them, and what is the intepreter for? I have that one open and I haven't used it yet after a couple of days.

Thanks again Legacy

thechristelegacy Aug 20th, 2004 2:17 AM

When the tutorial said command line, it meant the command line persion of Python, not that actual command window. The command line version of python is the interpreter. It runs things on the spot. For example, in the interpreter with the >>> prompt you can type hello world and hit enter and runs it right away (insteaf od saving it and running it with CMD.exe)

:

>>>print "Hello, World." #then you hit enter and see
Hello, World

It's basicly for doing things on the fly. And when you say editor do you mean Idle? You stated four things, when there are only three.

Quote:

Originally posted by Insomniac

here exists the editor for writing them, the shell for running them, command line for executing them, and what is the intepreter for

I believe you mean you have the editor (Idle), then you have the interpreter or shell which is the window with the >>> prompt, and then you have the command prompt (CMD.exe) to exicute the code. Hope that clears things up for ya!

Glad to see you got everyting working out. You'll be coding in no time :D

big_k105 Aug 20th, 2004 9:06 AM

can you give us the code you where using it mite help us figure out what could be wrong :)

Insomniac Aug 20th, 2004 9:34 PM

uhm....

yea, it's simple:

print "Hello."



:lol:



The problem was in trying to recall this program on the intepreter by 'hello.py'. I used to type that in and got nothing. But, after Legacies' patience, Im now able to pull up saved programs.

;)

erebus Aug 22nd, 2004 9:07 PM

Quote:

Originally posted by Insomniac@Aug 20 2004, 07:07 AM
Why do we use the CMD.exe ? That's simliar or it IS Dos, no? Dangit I read nowhere on those tutorials that says to open this specific line.
CMD is a command interpreter that issues with NT and up(NT, 2000, XP, Srv03). You could have just as easily used command.com which is the legacy aged MS-DOS derived command interpreter that uses external programs as shell commands. CMD has the comodity of having everything integrated and nicely packaged into the executable, and uses very little external programs for command execution. Hit F1 and find the DOS command reference for more information. Just a final note: command emulators on NT systems are NOT in any way DOS, since in that, you're calling them Disk Operating Systems. I can't say the same for 9x/Me :(. Hope that helped. Legacy got the rest of it just right.


All times are GMT -5. The time now is 11:13 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC