[Tutor] ANSI / VT100 Escape Codes in Windows 7 Environment

Chip Wachob wachobc at gmail.com
Wed Feb 27 13:28:02 EST 2019


Hello again,

As always, this list has been very helpful, and thank you.

So, I thought I was good to go until I attempted to run my code on a
Windows 7 vintage machine this morning.  The application is intended to be
run in the command window in Windows, from the terminal in Linux...

In the code I had included the ANSI escape characters so I could invert the
text and change the color.  Basically, I wanted to make the warning / error
messages stand out from the crowd.

Eg:
        # there's an error in the loop, report it
        # format reverse with yellow background
        print "\033[7m\033[33m"
        print " ERROR IN LOOP SIZE"
.
.
.
        # clear formatting
        print "\033[m"

As I have now learned, Windows 7 does not support this functionality.
Development had been done on a Windows 10 (and Ubuntu) machine where this
worked just fine.

I've been spending the morning looking at different solutions.  Many of
them seem to involve either including yet aother module, or, worse (IMHO) a
C library that will 'emulate' the ANSI escape sequences, API calls, etc.

Before I go tearing into my currently working code, I'm looking for
feedback from those much more experienced.

I need this code to run correctly on both Windows 7 and 10 (future Linux)
and I'm stuck with Python 2.7 due to other module limitations.

What do the experts out there suggest as the path of least pain and
suffering?

Again, thank you for your time and guidance.


More information about the Tutor mailing list