0

I am using Pycharm to edit some code and get a strange error when creating an enum:

class Colour(Enum):
    BLACK:   "\u001b[30m"
    RED:     '\u001b[31m'
    GREEN:   '\u001b[32m'
    OK:      "987"

The quoted strings (except for "987") are underlined red and hovering the cursor shows the message:

Statement expected, found BAD_CHARACTER

Single or double quotes make no difference

What is the problem here?

Mazerunner72
  • 613
  • 2
  • 6
  • 16
  • Those characters seem corrupted. What do you want to do exactly ? If you're trying to use unicode characters, it's in hexadecimal, so, this error is normal as there's a `[` and a `m` in it. If you want those actual strings, remove the unicode escape (`\u`) – Nenri Mar 29 '19 at 15:28
  • This is a mapping to ANSI terminal colours. Please see http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html for other examples – Mazerunner72 Mar 29 '19 at 15:32
  • I didn't know about those, tho u're missing the unicode string marker (IE `u"\u001b[30m"`) – Nenri Mar 29 '19 at 15:41
  • @Nenri: A `u"..."` string? In Python 3? – Matthias Mar 29 '19 at 15:44
  • 1
    That's not how you write an `enum` - use equal signs between the names and values, not colons. – jasonharper Mar 29 '19 at 15:46
  • yes, `u"..."` string still work, but i see that's not ur problem there. `\u001b` is unicode for `?` tho, so idk if ur console will interpret right the `?[30m` – Nenri Mar 29 '19 at 15:47
  • @jasonharper yep that did it :-) thank you. Should you make that an answer so I can credit you? – Mazerunner72 Mar 29 '19 at 15:50

0 Answers0