The following python code has some weird behavior which I don't understand
print('\x1bZ')
when I run this code whether in a file or in the interpreter I have a wierd outcome:
actual values as displayed when you write this value to a file as bytes:
Discoveries at time of posting this question:
- whether single quotes or double quotes make a difference (they don't)
0x1b
is hex for27
which in ascii is ESC which matches as displayed with the second picture. This lead me to theorize that the letterZ
in the string literal can be replaced but as per my test in point number 3 it cant be reproduced with other letters- instead of
\x1bZ
(ESC
and thenZ
) tryingESC
and then some other letter (I haven't checked all possibilities) yielded no apparent result except from replacingZ
withc
which seems to clear the terminal
Hypothesis that I came up with:
- This page may be relevant to the answer: https://pypi.org/project/py100/ because I have found a pattern there that resembles weird result:
Esc[?1;Value0c
whereValue
would be replaced by something. also^[[?1;<n>0c
appears in https://espterm.github.io/docs/VT100%20escape%20codes.html - Is this some encoding problem?
- Is this related to ANSI character escaping?
[?1;0c
vs[38;2;
which is used when changing background color of text
Questions:
- Why is this particular sequence of characters results in this output?
- What is VT100 and how it is related if it is related? (I visited it's Wikipedia page)
- whether it is possible to print a string that contains this specific sequence without that weird outcome as displayed in the first picture
all help and knowledge about this will be appreciated!!