How to replace characters that have already been printed in a previous line
Question: I am trying to make a game similar to [this](http://candies.aniwey.net/) in
Python (3.3.2 on Windows). I think that most of the programming is fairly
basic and so it will be easy for me as beginner. What I can't understand is
how to have a line of code that is constantly being changed while remaining in
the same location (I am trying to describe the amount of candies that you
have[if you look the line stays in the same place yet the physical str
changes]). I understand that you will have to do something like:

    
    
    candiesNbrDisplay = 'You have ' + str(candiesNbrOwned) + ' candies!'
    candiesNbrOwned = candiesNbrOwned + 1
    time.sleep( 1)
    

but how do you change the number without [this](http://imgur.com/mNj0A9S)!


Answer: This works on Unix (Mac OS X 10.8.5, with Python 2.7.2):

    
    
    import time
    import sys
    
    for i in xrange(1, 10):
        print "\rThe number of candies is %d and the pile is growing" % i,
        sys.stdout.flush()
        time.sleep(1)
    print ""
    

I don't know whether it will work on Windows or with Python 3.

