1

I'm trying to get this snippet to work, but it seems it won't work in Windows. Under Linux it works just fine!

Here is the sample snippet of code demonstrating the usage:

        tops = []
        for ind, top in enumerate(lr.top):
            color = colors.setdefault(top, COLORS[len(colors) % len(COLORS)])
            if top in disconnected_tops:
                top = '\033[1;4m' + top
            if len(lr.loss_weight) > 0:
                top = '{} * {}'.format(lr.loss_weight[ind], top)
            tops.append('\033[{}m{}\033[0m'.format(color, top))
        top_str = ', '.join(tops)

When the whole script is run, the escape character seems not to be working and weird characters show up on the screen. How do I get this to work on Windows?

2
  • Have you tried installing colorama ? Commented May 22, 2016 at 16:26
  • I'm using Anaconda, and I checked its installed Commented May 22, 2016 at 16:28

1 Answer 1

1

I found the problem!
I had to use init() in the script that was missing originally!.
Seems init() is not needed in Linux based OSes!since if it were!, this shouldn't had worked there in first place!
Ok.Here is the documentation itself!:

On Windows, calling init() will filter ANSI escape sequences out of any text sent to stdout or stderr, and replace them with equivalent Win32 calls.

On other platforms, calling init() has no effect (unless you request other optional functionality; see “Init Keyword Args”, below). By design, this permits applications to call init() unconditionally on all platforms, after which ANSI output should just work.

Sign up to request clarification or add additional context in comments.

3 Comments

Glad that your problem is solved. You can close this question by accepting your own answer by the way !
It takes 2 days for some one to accept his own answer, long gone are the days when you could immediately accept you answers ;-)
answer can be accepted now to prevent this coming up as unanswered

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.