On 8/10/2019 5:32 PM, Greg Ewing wrote:
Glenn Linderman wrote:
If that were true, the \n in the above example would already be a newline character, and the parsing of the format expression would not see the backslash. And if it were true, that would actually be far more useful for this situation.
But then it would fail for a different reason -- the same reason that this is a syntax error:
'hello world'
Would it really? Or would it, because it has already been lexed and parsed as string content by then, simply be treated as a new line that is part of the string? just like "hello\nworld" is treated after it is lexed and parsed? Of course, if it is passed back through the parser again, you would be correct. I don't know the internals that apply here. Anyway, Eric supplied the real reasons for the limitation, but it does seem like if it would be passed back through the "real" parser, that the real parser would have no problem handling the ord('\n') part of f"newline: {ord('\n')}" if it weren't prohibited by prechecking for \ and making it illegal. But there is also presently a custom parser involved, so whether the \ check is in there or in a preprocessing step before the parser, I don't know.