If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

simply stupid

alright so please no flaming me here. This is such a simple question

Im completely new to compilers/interpreters and have just started to take up learning python as a bit of a hobby

I have python27 installed and just started using the shell to learn.
I have noticed that I can't seem to write more than one line of code because every time I press enter it executes the line I just finished. then for shits and giggles I tried running the basic hello world from the cmd prompt and it asked what program to use to run it with.
I chose crimson editor as that is what I use for my site scripts. and it just showed the exact same things as the interpreter showed -> one line of code and the executed code.

How do I write multi-line code in the python shell without it running it everytime I press enter?
Why isn't it running from the cmd prompt?
I have completely overlooked something, I know. but this has never been my thing and its only recently I've tried to expand my thing, lol (not by whipping it against the bedpost or anything )

thanks

"In most gardens they make the beds too soft - so that the flowers are always asleep" - Tiger Lily

While i'm not a pro at python, i do have plenty of experience with other languages and in my experience it's because the command window (your program) closes after execution finishes. Which, for most learner programs, takes lest than .5 second.

Maybe try adding the following line at the end of your code. that way it waits for you to press something before ending

Code:

raw_input("Press Enter to continue...")

EDIT: Actually, I noticed that you are using 2.7 python. if you use Python 3 it is just input()

And its not stupid, you are just learning

Last edited by mungyun; August 18th, 2011 at 01:55 PM.

I believe in making the world safe for our children, but not our childrenís children, because I donít think children should be having sex. -- Jack Handey

I think his problem is that what he runs, opens and closes so fast that he cant see whats on that screen. I think if he adds that raw_input() line to the end of his code, he will be able to see his results.

I believe in making the world safe for our children, but not our childrenís children, because I donít think children should be having sex. -- Jack Handey

There is (time.sleep(seconds)) but generally i see examples that wait for keyboard input to continue. I prefer to wait for keyboard input but pause works just as well.

Edit:

IcSilk, I don't know what OS you use mainly but if you use Windows and have Visual Studio 2010 (Possibly just the express versions) there is a python addon for it that is pretty neat. Just downloaded it and it gives you an option for a python project and even gives you a graphical viewer for when you make graphical programs.

Even has error hilighting and auto indent. Pretty common but still neat.

Last edited by mungyun; August 18th, 2011 at 02:51 PM.

I believe in making the world safe for our children, but not our childrenís children, because I donít think children should be having sex. -- Jack Handey

I'm not a Python Wizard either (Wow do we all say this now? heh) But I do use Perl which is very similar from the point of view of the Computer; It's something that you typed instructions into, and then an Interpreter tells the Computer "He said to do this now with this and these options" much like a normal Interpreter would if you were having a Conversation with someone who didn't speak the Languages or Language you spoke.

I did grab some Python stuff for Windows, because like a year ago, I was bored one day, and I realized I could probably mess around with it for something to do. I don't normally do this stuff on Windows though because it kinda sucks.

I only have ONE machine with Windows even on it, and even then, it's ONE Partition, which has Windows 7 Installed on it, so I can play games and stuff. Everything else I have here, is running Linux, or BSD. And, in Linux and BSD, it's way easier.

For example; Say I'm working on a Perl Script that I want to do something with; Just as an example of course -

I open Vi, type out my Instructions that I want the Interpreter to tell my OS to do, and then save the file. I have options now, as to what I want to happen; I can save it a certain way, or, just name it "My_script.pl" and then make it executable.

From there, I type this command:

./My_script.pl

And it does so.

When I got Python stuff downloaded, I noticed that it was a whole lot like Perl, which is why I'm even telling you all this stuff, but, mainly, my point is that you may very well have an easier time just using Vi or Emacs, and then typing out the script, and then, having the Python Interpreter run it.