0

I'm using python 2.7 and i already look in:

Print in terminal with colors using Python?

Python Terminal Menu? Terminal Coloring? Terminal progress display?

And i still getting the same error. The running code is:

print '\033[1;31m' + '@%s:' + '[1;m' + '\033[1;32m' + '%s - id = %s\n' + '\033[1;m' % (status.text1.encode('utf-8'), status.text2.encode('utf-8'), status.text3.encode('utf-8'))

And the error obatained is:

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    mostrar()
  File "C:\Documents and Settings\Administrador.DESKTOP\Mis documentos\test.py", line 16, in mostrar
        print '\033[1;31m' + '@%s:' + '[1;m' + '\033[1;32m' + '%s - id = %s\n' + '\033[1;m' % (status.text1.encode('utf-8'), status.text2.encode('utf-8'), status.text3.encode('utf-8'))
TypeError: not all arguments converted during string formatting

Like you can see, i'm using python in windows.

The question is how to avoid the error? I already use colorama, and the error is the same.

Community
  • 1
  • 1
X3MBoy
  • 203
  • 4
  • 12

1 Answers1

1

Try putting parentheses around the format strings you are concatenating. % binds with a higher precedence than +, so the error comes from:

'\033[1;m' % (... 3 arguments ...)
scav
  • 1,095
  • 1
  • 9
  • 17