Python Help

Started by
19 comments, last by Polantaris 17 years, 10 months ago
I've decided to start trying to learn Python, and I'm reading the Tutorial that coems with the program. It's showing me how to do the "Interperter" or whatever it's called and it shows this: >>> 2+2 4 >>> # This is a comment ... 2+2 4 How do I get the ... after the # This is a comment? I would think its some kind of extra code or something you have to type, but I can't find where the Tutorial explains how to get this. Can anyone help me?
~Polantaris
Advertisement
You can think of an interpreter as a way to execute python code in real time. If you're familiar with compilers, it's essentially the same thing only instead of generating an executable file, it runs your code then and there.

Anyway, what exactly are you trying to get here? You want to type a comment into the interpreter and have the next line print an elipse (...)? Out of context I'm not sure what the example in the book is supposed to mean, but perhaps if you clarify a bit we can help you out.
Without order nothing can exist - without chaos nothing can evolve.
You type it exactly as in the tutorial. That is, type the comment and hit enter, you'll see the ellipse. :-)


Hope this helps.
Okay with the main problem I'm getting here, is that

This is what it says exactly on the Tutorial
In the following examples, input and output are distinguished by the presence or absence of prompts (">>> " and "... "): to repeat the example, you must type everything after the prompt, when the prompt appears; lines that do not begin with a prompt are output from the interpreter. Note that a secondary prompt on a line by itself in an example means you must type a blank line; this is used to end a multi-line command.

>>> is supposed to be like the beginning of a mutli-lined code or a single line code, and ... is supposed to be continuing a multi-lined code, or that's what I think. Either way, it never really explains how to get to ..., which is why I'm confused. I'm just trying to do the examples in the Tutorial so that I can learn the basics.

stuff with nothing before is is output, and the rest is input.

Also, is there a Non-Interperter with Python, or is all real-time execution? The only load up stuff that gets added to my start bar is interperters. Therefore, I just assume that's how it goes.
~Polantaris
Assuming you are using IDLE, I thought it did it automatically. I haven't used it in a while, but I thought it wouldn't evaluate until there is a complete statement.

Quote:Original post by Polantaris
Also, is there a Non-Interperter with Python, or is all real-time execution? The only load up stuff that gets added to my start bar is interperters. Therefore, I just assume that's how it goes.


There are multiple IDEs for python. When you download the interpretor it come with IDLE (which is what I assume you are already using). You should be able to "creat new file" or something that will bring up a new window.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
Quote:Original post by Anonymous Poster
You type it exactly as in the tutorial. That is, type the comment and hit enter, you'll see the ellipse. :-)


Hope this helps.


I guess not, because when I hit Enter, it just gives me another >>>, unless its supposed to? The Tutorial is alittle confusing if you ask me.
~Polantaris
Quote:Original post by Polantaris
I guess not, because when I hit Enter, it just gives me another >>>, unless its supposed to? The Tutorial is alittle confusing if you ask me.


Yeah, it's normal. Don't worry about it.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Oh alright. Is there a normal non-real-time compiler for Python? If not, how do I do big projects with it then?
~Polantaris
I'm on Windows and it works for me. I see

>>>

And I type just the hash(pound) sign and enter. It gives me

>>> #
...

You might have to say what version of python you're using and what OS.

You can do big projects and run them from the command line like so:

python myprog.py

where myprog.py is a python script you wrote.
Quote:Original post by Polantaris
Oh alright. Is there a normal non-real-time compiler for Python? If not, how do I do big projects with it then?


If you're using IDLE, hit CTRL+N (or File->New Window). It'll give you a text editor window in which you can write your code. Save it (with a .py extension), then use the Shell and Run menus.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement