Sign in to follow this  
Polantaris

Python Help

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Boder, the whole thing that was confusing me was the fact that I didnt get ... I got
>>> #
>>>

not
>>> #
...

and that's why I was confused.

Okay Fruny, thanks for telling me that, I understand how it works now.

Share this post


Link to post
Share on other sites
Quote:
Original post by Polantaris
Boder, the whole thing that was confusing me was the fact that I didnt get ... I got
>>> #
>>>

not
>>> #
...

and that's why I was confused.

Actually, you are seeing the correct behavior.

The ellipses (...) represent a continuation of a statement block. However, a comment is not a statement, much less a statement block. It is completely ignored by the compiler/interpreter, so it shouldn't modify the parser state and thus prompt you for a continuation.

In other words, the tutorial is, in this instance at least, wrong.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Actually, the Python interpreter on Linux did exactly as in the tutorial (that is, after typing a comment, I got an ellipse). Is it possible that the command line interpreter on Windows has a slightly different behaviour than that of Idle? I don't use Windows so I can't verify that.

To the original poster: sorry if my post mislead you. I tried your code in the command line interpreter in Linux and (wrongly) assumed that the behaviour would be consistent between implementations. I've never read the tutorial either (I'm not a pythonista).


Hope this helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Actually, the Python interpreter on Linux did exactly as in the tutorial (that is, after typing a comment, I got an ellipse). Is it possible that the command line interpreter on Windows has a slightly different behaviour than that of Idle? I don't use Windows so I can't verify that.

The implementation of the Windows interpreter is actually irrelevant. The question here is What is semantically correct? Obviously, the interpreter should wholly ignore comments (they should have the same effect as simply hitting enter, which should present you with another prompt, not a continuation prompt).

In summary, the "interpreter on Linux" (what version?) is broken.

Share this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
In summary, the "interpreter on Linux" (what version?) is broken.


Actually, the command-line version of the interpreter on Windows behaves the same (prints the ...). So I guess it is a difference in the read-eval-print loops between the command-line and IDLE-embedded interpreters.

Share this post


Link to post
Share on other sites
Quote:
Original post by Fruny
Quote:
Original post by Oluseyi
In summary, the "interpreter on Linux" (what version?) is broken.

Actually, the command-line version of the interpreter on Windows behaves the same (prints the ...). So I guess it is a difference in the read-eval-print loops between the command-line and IDLE-embedded interpreters.

Then they're both broken. [smile]

Sorry, don't have an interpreter installed on this machine.

Share this post


Link to post
Share on other sites
I dunno, I think I'm going to look for an online guide when I get home from school anyway, because that tutorial is very confusing, and isn't very understandable to me. Oh well, thanks for the help though.

Share this post


Link to post
Share on other sites
Alright now I have a new problem. I'm working on PyGame, with a tutorial from http://rene.f0o.com/mywiki/LectureOne It tells me to put the following down. It's obviously there to set the folder settings and such, in the Python command line (Dos version I guess), but I continually get syntax errors from PATH on the first line. I'm not too good at Python yet, being my first day with it, so I don't know what that command is, so I don't know how to fix it. (I noticed he still uses Python23 as the folder, but they are at Python24 as the folder name, so I changed it accordingly, was that a mistake?)

set PATH=%PATH%;c:\Python23
cd "\Program Files\Pygame-Docs\examples"
python chimp.py

Share this post


Link to post
Share on other sites
No, that goes on the *DOS* command line. It's for setting up the DOS prompt so that it knows where the Python interpreter executable (python.exe) is located, so that you can actually run scripts on the command line (with commands like 'python chimp.py') without the thing complaining.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this