#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Location
    United States
    Posts
    2
    Rep Power
    0

    Error in Eclipse (w/ PyDev) vs Python Shell?


    Hi all, I am relatively new to programming in general but trying to learn as much as I can while I chug along. Up until this point I haven't really looked for programming forums to join and post to, inquire, ask for feedback but this seemed like a good time.

    I am trying to write a text based rpg in Python (3.3) and so far it has proved to be a great beginner challenge. Earlier today I was thinking about how I see text output in many games where it is displayed one letter at a time in a text bubble rather than the whole bubble being output at once. I read up on the Python docs about the
    Code:
    sleep()
    function and wrote a little function to fancy up my text output:

    Code:
    def outputText(text):
        for i in text:
            print(i, end='')
            time.sleep(0.03) #requires 'import time'
        return
    This spits out whatever string I would dump into it in a pretty slick manner and works great when using IDLE and executing the script in the Python shell but when I run it in Eclipse it doesn't display anything in the console until the while thing would be done printing.

    Like, say I have have a string of 10 letters and told Python to sleep for 1 second between printing each letter as it iterates through the string. In the Python shell it would print a letter every second, where as Eclipse will sit there blank for the whole 10 seconds and then finally print the completed string. This only seems to be a problem when using the
    Code:
    end=''
    in the print function so that everything is on the same line. If I were to just use
    Code:
    print(i)
    , Eclipse works fine.

    Do you guys have and input or suggestions?

    Thank you,
    Akayllin
  2. #2
  3. Contributing User

    Join Date
    Aug 2011
    Posts
    5,223
    Rep Power
    503

    buffering lessons


    It's all working correctly. You're learning about buffered output.

    after your print(i,end='') statement use
    sys.stdout.flush() # requires import sys
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Location
    United States
    Posts
    2
    Rep Power
    0
    Originally Posted by b49P23TIvg
    It's all working correctly. You're learning about buffered output.

    after your print(i,end='') statement use
    sys.stdout.flush() # requires import sys
    Ah, that works! Could you explain a little more why this is different in Eclipse? Is it just the way PyDev is made?
  6. #4
  7. Contributing User

    Join Date
    Aug 2011
    Posts
    5,223
    Rep Power
    503
    I'm a numerical analyst, physics modeling programmer, not a system's guy.

    I'm not sure how useful it is to explain terminal capabilities, echo, noecho, buffered, unbuffered.
    See the termcap library. I wrote a character cell version of minesweeper using termcap. It can play many more "obvious" moves than do other versions I've seen. The games are fast, fun to watch, and controlled with keyboard not mouse. Here's the link, (look for the c version) but I cannot access the site now. I don't know how broken the web site is---there's never been trouble before and I've been posting programs to implement the various algorithms in python, FORTRAN, c, and j for several years. They're trying to install captcha to verify who posts at the wiki.

    Or about the IBM 3270 computer terminal of 1971 which had an editor built in. The system buffered a screenful at once. Clever! IBM offloaded editing tasks from the mainframe.

    IDLE uses TCL, which on my system probably uses X11. Sure, I've read the 3 XLib books a couple times. I know about the fun one can have with the various line joining algorithms.

    Digital communications seem to work more efficiently using fewer, larger chunks as opposed to many small conversations. (Fewer packet headers flying around, for one thing. The rule also holds data completely internal to your computer as well.)

    That's background information which is, I expect, mostly correct. I really can't help otherwise.
    Last edited by b49P23TIvg; January 12th, 2014 at 05:32 PM.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo