Thread: Red Bull fun...

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

    Join Date
    Jun 2013
    Posts
    12
    Rep Power
    0

    Red Bull fun...


    I was just messing around and making a dumb little program for practice and wrote this:

    RedBull

    I was wondering... how do I make it to where it updates the number on a single line and the print statements "replace" themselves?

    so instead of:

    "blah blah blah"
    "blah bleh blah"

    95
    90
    85
    ...

    It prints it like this:

    "blah blah blah" -- Alert Level: 95

    and just updates that one line instead of printing a new one?

    Sorry its hard to explain what I mean...

    Zach
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,851
    Rep Power
    481
    You either use a gui
    tkinter

    Or you use an ANSI terminal with termcap (I guess it's called curses or ncurses now-a-days)

    Or perhaps backspace would work. '\b' Or is that bell?
    In c the escapes are:

    \a Bell (beep)
    \b Backspace
    \f Formfeed
    \n New line
    \r Carriage return
    \t Horizontal tab
    \\ Backslash
    \' Single quotation mark
    \" Double quotation mark
    \ooo Octal representation
    \xdd Hexadecimal representation
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Usually Japan when not on contract
    Posts
    240
    Rep Power
    12
    Originally Posted by b49P23TIvg
    Or you use an ANSI terminal with termcap (I guess it's called curses or ncurses now-a-days)
    Small clarification...

    curses has been around since 1980 and ncurses is "new curses", an open source superset of the original curses library that came out in the early 1990's. It abstracts the character cell instruction stuff that is involved in writing a text-based GUI (including mouse input and other things). Prior to curses each vendor provided its own library for their own terminal, which was a pain because buying a different terminal type meant you needed to use a different library to draw stuff all pretty on it because the library talked directly to the controller in most cases.

    "termcap" is short for "terminal capabilities" and is a digest of a bazillion terminal types and what their standard sizes, colors, feature availability, connector types and other stuff is. These days nearly every terminal is virtual and emulates the VT100 or a superset of that with a variable size.

    Using this kind of library you can declare that a field on the screen contains value X and that when X is updated that field should be redrawn. To do it without such a library would get into you having to send terminal cell commands to the system via Python -- which would be pretty cumbersome.

IMN logo majestic logo threadwatch logo seochat tools logo