New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimized the print_with_magic_color() function. #84
Conversation
The function was originally generating a random number from 0,255 and then was checking if that number is form the excluded number and till it finds the number from accepted number range , it kept looping in a while loop. This was replaced by using random.choice([accepted int list]) instead.Added annotations , doc string and removed the bool comparison (if bool_value==True:(bad practice) , if bool_value:(good practice). Removed unnecessary string formatting which makes the code un readable and %string formatting might be deprecated in the near future.
I was calling random.choice on an int. Fixed that and also the imports
Sorry for that . I have fixed the bug now . |
To make sure every time the function is called the text is printed on a new line.
We are getting an exception for the function you modified. Here are the exception details. Its an "UnicodeEncodeError". Error Details : ['Traceback (most recent call last):\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\ClointFusion\ClointFusion.py", line 203, in print_with_magic_color\n print(color+ch+res,end="")\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py", line 41, in write\n self.__convertor.write(text)\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py", line 162, in write\n self.write_and_convert(text)\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py", line 187, in write_and_convert\n self.write_plain_text(text, cursor, start)\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py", line 195, in write_plain_text\n self.wrapped.write(text[start:end])\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line 19, in encode\n return codecs.charmap_encode(input,self.errors,encoding_table)[0]\n', "UnicodeEncodeError: 'charmap' codec can't encode character '\u2764' in position 0: character maps to \n", '\nDuring handling of the above exception, another exception occurred:\n\n', 'Traceback (most recent call last):\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\ClointFusion\ClointFusion.py", line 206, in print_with_magic_color\n print(color+ch+res,end="")\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py", line 41, in write\n self.__convertor.write(text)\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py", line 162, in write\n self.write_and_convert(text)\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py", line 187, in write_and_convert\n self.write_plain_text(text, cursor, start)\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py", line 195, in write_plain_text\n self.wrapped.write(text[start:end])\n', ' File "C:\Users\USER NAME\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line 19, in encode\n return codecs.charmap_encode(input,self.errors,encoding_table)[0]\n', "UnicodeEncodeError: 'charmap' codec can't encode character '\u2764' in position 0: character maps to \n"] |
Okay Sir , I will fix this issue. Can you share the code which can recreate
this bug? So that I can find the cause and solve the problem.
The bug seems based more on how the function is getting called (probably a
trailing '\n' is causing the unicode error), so I need to check that.
Thank you
Sagar Abhyankar
…On Mon, Nov 1, 2021 at 8:26 PM Murali Manohar Varma < ***@***.***> wrote:
We are getting an exception for the function you modified. Here are the
exception details.
Its an "UnicodeEncodeError".
For time being, we restored the logic.
Please work on this and make a PR.
Error Details : ['Traceback (most recent call last):\n', ' File
"C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\ClointFusion\ClointFusion.py",
line 203, in print_with_magic_color\n print(color+ch+res,end="")\n', ' File
"C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py",
line 41, in write\n self.__convertor.write(text)\n', ' File "C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py",
line 162, in write\n self.write_and_convert(text)\n', ' File "C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py",
line 187, in write_and_convert\n self.write_plain_text(text, cursor,
start)\n', ' File "C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py",
line 195, in write_plain_text\n self.wrapped.write(text[start:end])\n', '
File "C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line
19, in encode\n return
codecs.charmap_encode(input,self.errors,encoding_table)[0]\n',
"UnicodeEncodeError: 'charmap' codec can't encode character '\u2764' in
position 0: character maps to \n", '\nDuring handling of the
above exception, another exception occurred:\n\n', 'Traceback (most recent
call last):\n', ' File "C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\ClointFusion\ClointFusion.py",
line 206, in print_with_magic_color\n print(color+ch+res,end="")\n', ' File
"C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py",
line 41, in write\n self.__convertor.write(text)\n', ' File "C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py",
line 162, in write\n self.write_and_convert(text)\n', ' File "C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py",
line 187, in write_and_convert\n self.write_plain_text(text, cursor,
start)\n', ' File "C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\site-packages\colorama\ansitowin32.py",
line 195, in write_plain_text\n self.wrapped.write(text[start:end])\n', '
File "C:\Users\USER
NAME\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line
19, in encode\n return
codecs.charmap_encode(input,self.errors,encoding_table)[0]\n',
"UnicodeEncodeError: 'charmap' codec can't encode character '\u2764' in
position 0: character maps to \n"]
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#84 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASEGADJUY6BFCGR5NLQVJ3TUJ2TAXANCNFSM5GQTV56Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
The function was originally generating a random number from 0,255 and then was checking if that number is from the excluded numbers (for color ints) and till it finds the number from accepted number range , it kept looping in a while loop. This was replaced by using random.choice([accepted int list]) instead.
Added annotations , doc string and removed the bool comparison (if bool_value==True:(bad practice) , if bool_value:(good practice). Removed unnecessary string formatting which makes the code un readable and %string formatting might be deprecated in the near future.