x
Out[18]: '\x1b[24m\x1b[1m\x1b[2;1HPressure Index \r\n'
print x
Pressure Index
str(x)
Out[20]: '\x1b[24m\x1b[1m\x1b[2;1HPressure Index \r\n'
x.__str__()
Out[21]: '\x1b[24m\x1b[1m\x1b[2;1HPressure Index \r\n'
I don't understand how the print statement cleans up all the garbage characters in the variable. I already have a work around, by splitting the text after "1H" and stripping the new line characters, but I am curious how I could do this more rigorously and get the clean output of print to become my variable. What is it that the print statement is doing to clean up the text?
After doing some further reading, I tried to implement __str__
as part of a class, but I am having trouble implementing this. Below is my first attempt
class readable(str):
def __str__(self):
return str(self)
But I still get
y=readable(x)
y
Out[50]: '\x1b[24m\x1b[1m\x1b[2;1HPressure Index \r\n'
EDIT: The output that I want is the print statement output. I am trying to strip my variable of all the extra characters so that it will just be a string reading 'Pressure Index'