Closed Thread
Results 1 to 5 of 5

Thread: n00b problem with an editor

  1. #1
    WIlfred86 is offline Newbie
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

    n00b problem with an editor

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    CallBackGuy is offline Newbie
    Join Date
    Mar 2009
    Posts
    29
    Rep Power
    0

    Re: n00b problem with an editor

    Quote Originally Posted by WIlfred86 View Post
    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
    I think functions is what you're looking for.
    Code:
    def hello():
        print 
    "Hello"
        
    print "Helloagain" 
    And then just type the function name to run it
    Code:
    hello() 
    Code:
    penzilla.net/tutorials/python/functions/
    Last edited by CallBackGuy; 03-06-2009 at 11:24 PM.

  4. #3
    WIlfred86 is offline Newbie
    Join Date
    Mar 2009
    Posts
    3
    Rep Power
    0

    Re: n00b problem with an editor

    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:

    Code:
    def newLine():
    print 
    Then you have to write something like:

    Code:
    print "1st Line"
    newLine()
    print 
    "2nd Line" 
    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.

    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

  5. #4
    v0id is offline Retired
    Join Date
    Apr 2007
    Posts
    2,937
    Blog Entries
    3
    Rep Power
    42

    Re: n00b problem with an editor

    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.

  6. #5
    Tynach's Avatar
    Tynach is offline Newbie
    Join Date
    Apr 2009
    Location
    IDP base in D#0
    Posts
    9
    Rep Power
    0

    Re: n00b problem with an editor

    Use \n.

    Code:
    print "Hello\nHelloagain" 
    \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.

    Edit 1: I read your other post about the function. That function is stupid, honestly, as you could do this:

    Code:
    print "Hello\n\nHelloagain" 
    to get the empty line in the middle. Or, more traditionally (and not using a realtime interpreter), to do this:

    Code:
    print "Hello\n"
    print "Helloagain" 
    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"
    raw_input() 
    Save that in a text file, probably named hello.py, and double-click the hello.py file.

    Two text editors I recommend are Notepad++ and Kate.

    Edit 2: to make the function:

    Code:
    def newline():
        print

    print 
    "Hello"
    newline()
    print 
    "Helloagain"
    raw_input() 
    The raw_input really waits for you to type something and press Enter. That's why I put it in there.
    Last edited by Tynach; 04-04-2009 at 05:39 PM.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. n00b Object Scope question
    By belch85 in forum C# Programming
    Replies: 5
    Last Post: 11-23-2010, 06:36 AM
  2. n00b question
    By bajerocks in forum C and C++
    Replies: 3
    Last Post: 04-04-2010, 11:12 AM
  3. Replies: 3
    Last Post: 01-15-2010, 11:54 PM
  4. Replies: 17
    Last Post: 09-27-2008, 08:45 AM
  5. n00b class question
    By MerakSpielman in forum C and C++
    Replies: 15
    Last Post: 02-20-2008, 08:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts