icecream strange output
new to icecream with 2.1.3 on windows python38
from icecream import ic
ic("progress remark")
produces garbage: round my text:- ============= RESTART: C:/Python/Python38/OurStuff/icecream-test.py ============ [38;5;247mic[39m[38;5;245m|[39m[38;5;245m [39m[38;5;36m'[39m[38;5;36mprogress remark[39m[38;5;36m'[39m
other uses if ic() are no better.
Same problem -
see: https://pastebin.com/qpw23VTW
Using Python 3.10
Also tried in the shell directly
>>>from icecream import ic
>>>var_1 = 1
>>>ic(var_1)
[38;5;247mic[39m[38;5;245m|[39m[38;5;245m [39m[38;5;247mError[39m[38;5;245m:[39m[38;5;245m [39m[38;5;247mFailed[39m[38;5;245m [39m[38;5;247mto[39m[38;5;245m [39m[38;5;247maccess[39m[38;5;245m [39m[38;5;247mthe[39m[38;5;245m [39m[38;5;247munderlying[39m[38;5;245m [39m[38;5;247msource[39m[38;5;245m [39m[38;5;247mcode[39m[38;5;245m [39m[38;5;100mfor[39m[38;5;245m [39m[38;5;247manalysis[39m[38;5;245m.[39m[38;5;245m [39m[38;5;247mWas[39m[38;5;245m [39m[38;5;247mic[39m[38;5;245m([39m[38;5;245m)[39m[38;5;245m [39m[38;5;247minvoked[39m[38;5;245m [39m[38;5;100min[39m[38;5;245m [39m[38;5;247ma[39m[38;5;245m [39m[38;5;247mREPL[39m[38;5;245m [39m[38;5;245m([39m[38;5;247me[39m[38;5;245m.[39m[38;5;247mg[39m[38;5;245m.[39m[38;5;245m [39m[38;5;166mfrom[39m[38;5;245m [39m[38;5;136mthe[39m[38;5;245m [39m[38;5;247mcommand[39m[38;5;245m [39m[38;5;247mline[39m[38;5;245m)[39m[38;5;245m,[39m[38;5;245m [39m[38;5;247ma[39m[38;5;245m [39m[38;5;247mfrozen[39m[38;5;245m [39m[38;5;247mapplication[39m[38;5;245m [39m[38;5;245m([39m[38;5;247me[39m[38;5;245m.[39m[38;5;247mg[39m[38;5;245m.[39m[38;5;245m [39m[38;5;247mpackaged[39m[38;5;245m [39m[38;5;100mwith[39m[38;5;245m [39m[38;5;247mPyInstaller[39m[38;5;245m)[39m[38;5;245m,[39m[38;5;245m [39m[38;5;100mor[39m[38;5;245m [39m[38;5;247mdid[39m[38;5;245m [39m[38;5;247mthe[39m[38;5;245m [39m[38;5;247munderlying[39m[38;5;245m [39m[38;5;247msource[39m[38;5;245m [39m[38;5;247mcode[39m[38;5;245m [39m[38;5;247mchange[39m[38;5;245m [39m[38;5;247mduring[39m[38;5;245m [39m[38;5;247mexecution[39m[38;5;166m?[39m
1
I have the same problem in idle,my output is this:
[38;5;247mic[39m[38;5;245m|[39m[38;5;245m [39m[38;5;247ma[39m[38;5;245m:[39m[38;5;245m [39m[38;5;36m10[39m [38;5;247mic[39m[38;5;245m|[39m[38;5;245m [39m[38;5;247mA[39m[38;5;245m([39m[38;5;36m5[39m[38;5;245m)[39m[38;5;245m:[39m[38;5;245m [39m[38;5;36m10[39m [38;5;247mic[39m[38;5;245m|[39m[38;5;245m [39m[38;5;247mB[39m[38;5;245m([39m[38;5;36m10[39m[38;5;245m)[39m[38;5;245m:[39m[38;5;245m [39m[38;5;36m20[39m
and this is my code:
`from icecream import ic, argumentToString, stderrPrint
a = 10 ic(a)
def A(num): return num + 5 def B(num): return num + 10
ic(A(5)) ic(B(10))
print(a) `
I have the same problem in idle,my output is this:
�[38;5;247mic�[39m�[38;5;245m|�[39m�[38;5;245m �[39m�[38;5;247ma�[39m�[38;5;245m:�[39m�[38;5;245m �[39m�[38;5;36m10�[39m �[38;5;247mic�[39m�[38;5;245m|�[39m�[38;5;245m �[39m�[38;5;247mA�[39m�[38;5;245m(�[39m�[38;5;36m5�[39m�[38;5;245m)�[39m�[38;5;245m:�[39m�[38;5;245m �[39m�[38;5;36m10�[39m �[38;5;247mic�[39m�[38;5;245m|�[39m�[38;5;245m �[39m�[38;5;247mB�[39m�[38;5;245m(�[39m�[38;5;36m10�[39m�[38;5;245m)�[39m�[38;5;245m:�[39m�[38;5;245m �[39m�[38;5;36m20�[39mand this is my code:`from icecream import ic, argumentToString, stderrPrint
a = 10 ic(a)
def A(num): return num + 5 def B(num): return num + 10
ic(A(5)) ic(B(10))
print(a) `
but I can use that in pycharm, I don't know why.
This problem still exists nearly a year later. (running on mac mini via IDLE using Python3.8
from icecream import ic a =123 ic(a)
[38;5;247mic[39m[38;5;245m|[39m[38;5;245m [39m[38;5;247ma[39m[38;5;245m:[39m[38;5;245m [39m[38;5;36m123[39m
''' test icecream '''
from icecream import ic
answer = 'hola mondo'
ic(answer)
Output from the above code on a Mac or a RISC OS machine is a string of escape sequences and commands. RISC OS and Mac terminal handlers do not decode the string and it appears as below.
The strings are documented in: "Standard ECMA -48 "Control Functions for Coded Character Sets"
On my windows 10 machine the string appears as: answer = 'hola mondo' the text is coloured a greenish blue.
In conclusion I think this issue is NOT with Icecream but with the users' machine setup.
here is the ouput from the code on RISC OS and Mac OS:
[38;5;247mic[39m[38;5;245m|[39m[38;5;245m [39m[38;5;247manswer[39m[38;5;245m:[39m[38;5;245m [39m[38;5;36m'[39m[38;5;36mhola mondo[39m[38;5;36m'[39m [0
here it is annotated and split into components for easier reading:
NB [ is an escape or Control Sequence Introducer
[38;5;247m # foreground color from 256: light grey ic [39m # cursor forward 1 [38;5;245m # foreground color from 256 : darker grey | [39m [38;5;245m [39m [38;5;247m answer # my variable name [39m [38;5;245m : [39m [38;5;245m [39m [38;5;36m # foreground colour dark cyan ' [39m [38;5;36m hola mondo # my variable value [39m [38;5;36m' [39m * [0m*
ha! it seems to be the same problem I had with colorama.
in windows the escape sequences work when the program is executed by python in the console, but not when run from my IDLE.
I shall be using f-strings for diagnostics anyway.
ha! it seems to be the same problem I had with colorama. in windows the escape sequences work when the program is executed by python in the console, but not when run from my IDLE. I shall be using f-strings for diagnostics anyway.
On Mon, 13 Nov 2023 at 19:28, john rickman @.***> wrote:
''' test icecream ''' from icecream import ic answer = 'hola mondo' ic(answer)
Output from the above code on a Mac or a RISC OS machine is a string of escape sequences and commands. RISC OS and Mac terminal handlers do not decode the string and it appears as below.
The strings are documented in: "Standard ECMA -48 "Control Functions for Coded Character Sets"
On my windows 10 machine the string appears as: answer = 'hola mondo' the text is coloured a greenish blue.
In conclusion I think this issue is NOT with Icecream but with the users' machine setup.
here is the ouput from the code on RISC OS and Mac OS:
[38;5;247mic[39m[38;5;245m|[39m[38;5;245m [39m[38;5;247manswer[39m[38;5;245m:[39m[38;5;245m [39m[38;5;36m'[39m[38;5;36mhola mondo[39m[38;5;36m'[39m [0
here it is annotated and split into components for easier reading:
NB [ is an escape or Control Sequence Introducer
[38;5;247m # foreground color from 256: light grey ic [39m # cursor forward 1 [38;5;245m # foreground color from 256 : darker grey | [39m [38;5;245m [39m [38;5;247m answer # my variable name [39m [38;5;245m : [39m [38;5;245m [39m [38;5;36m # foreground colour dark cyan ' [39m [38;5;36m hola mondo # my variable value [39m [38;5;36m' [39m * [0m*
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
-- Nick "Mac" McElwaine
Here is a solution to the 'strange output ' issue.
'''
test icecream
'''
import sys
from icecream import ic
# direct sys.stderr to a file
sys.stderr = open('log.txt', 'w')
msg = 'This is an error message'
# the following print satement will go to file log.txt
print(msg, file=sys.stderr)
# ic output is written to file log.txt
ic (msg)
ic ('hola mondo')
# this print goes to the console
print('Adiós mondo cruel - output to stdout')
Here are three ways to run script ice.py with sensible output from icecream ic() to log.txt. Note however that the colors are stripped out.
-
use a command file containing: python3 ice.py 1>p_out 2>p_err
(stdout goes to p_out p_err is created but stderr goes to log.txt)
-
directly from console using command python3 ice.py 1>p_out 2>p_err
(stdout goes to console stderr goes to log.txt)
-
use import from python shell: python3
import ice (stdout goes to console stderr goes to log.txt pycache is created)
In 1 and 2 above the redirect "2>p_err" in the command is over-ridden by the python code: sys.stderr = open('log.txt', 'w')
There is a simpler solution. You need to open the library file (for me it is located at C:\Users\User\AppData\Local\Programs\Python\Python312\Lib\site-packages\icecream\icecream.py)
In line 81 put colored = s. The conclusion will be correct.
If you want normal(no red text) in 69 line put print(*args).
thankyou all for your excellent input. I now realie that all mu colorama and icecream problems arise because I run my programs inside IDLE,