Python 2.7.6 - Printing a string on a fixed position while creating a dynamic histogram
Question: I created a little script that check virtual memory and how much is being
used. According to the number that comes back it creates a histogram. The
original script creates the following output.

    
    
    VIRT MEMORY USAGE:  43.5
    0----------------100%
    ||||||||
    

However I want the output to be like

    
    
    VIRT MEMORY USAGE:  43.5
    0||||||||        100%
    

The problem I am having is that the "100%" is not in a fixed position. It will
move left or right according to how many "|" are being generated by the loop.
This does not create the effect desired. :(

The code follows below.

    
    
    #!/usr/bin/python
    import psutil
    import socket
    
    print "Hostname: ", (socket.gethostname())
    print ""
    virtu_full_num = psutil.virtual_memory().percent
    print "VIRT MEMORY USAGE: ", virtu_full_num
    #print "0----------------100%" # From original version of script
    
    number = int(float(psutil.virtual_memory().percent))
    
    for loop_hist in range (1):
         number = number / 10
         print  "0 %s "  % ("||" *number), "   100"
         #print "%s" % ("||" *number)  #From original version of script
    


Answer: It should be pretty straightforward. Figure out how many space characters
there would be between `0` and `100`. For every `|` character you add, remove
one space character. Add the two up at the end, and you should be all set.

