Hello everybody,
I just started to learn Python, and I am using the PythonWin editor from Activestate to write code.
Maybe this is a silly question, but when I want to write for example:
print "Hello"
print "Helloagain"
it only prints the first line, because when I press return to go to the next line, it executes the first print command.
Is there some way to bypass this, without resorting to writing this code in a "normal text" editor, save it, and then execute it? I like this realtime way of seeing what my code does.
Best regards,
Wilfred
Last edited by WIlfred86; 03-06-2009 at 06:12 AM. Reason: spelling errors
Last edited by CallBackGuy; 03-06-2009 at 11:24 PM.
CallBackGuy, thank you for your fast reply. However, I was more specifically referring to an example in a book wich I encountered (I'm sorry I didn't mentioned that earlier).
I am learning Python now from an ebook called "How to think like a computer scientist - learning with python"
In some of the examples in the book you make this function first:
Then you have to write something like:Code:def newLine():
When I want to write this text "realtime" it executes only "1st Line". Maybe this is normal, but I wanted to make sure (if) there is some way of dealing with this, for example a special key-combination to prevent the code executing immediately.Code:print "1st Line"
newLine()
print "2nd Line"
By the way, I'm making progress now. I am now learning the and or if then operators. I even made myself an infinite loop by accident (a function that called itself)
Best regards, and thank you for your help,
Wilfred
Normally would the line in the function you showed us just print a blank line, and should not wait for input. I have never stumbled upon the behavior you describe with the print-statement. I know this isn't the advice you hoped to get, but I suggest you to see if something's wrong with your interpreter, as that isn't normal behavior.
Use \n.
\n is the newline character, and it will interpret it as making everything after it appear on a new line. You don't need spaces around it or anything, just put it in there. Yes, it looks weird.Code:print "Hello\nHelloagain"
Edit 1: I read your other post about the function. That function is stupid, honestly, as you could do this:
to get the empty line in the middle. Or, more traditionally (and not using a realtime interpreter), to do this:Code:print "Hello\n\nHelloagain"
By the way, in Windows, you can just run a Python script by double-clicking the .py file. Though, if it's something like above, it runs and exits quickly. So, just put raw_input() at the end:Code:print "Hello\n"
print "Helloagain"
Save that in a text file, probably named hello.py, and double-click the hello.py file.Code:print "Hello\n"
print "Helloagain"
raw_input()
Two text editors I recommend are Notepad++ and Kate.
Edit 2: to make the function:
The raw_input really waits for you to type something and press Enter. That's why I put it in there.Code:def newline():
print "Hello"
newline()
print "Helloagain"
raw_input()
Last edited by Tynach; 04-04-2009 at 05:39 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks