i am trying to write a python program that prints music notes (like -> u1d15e). However, i cant quite get it to work.
Here is what i get using the following code
note = '\U0001d15e'
bytes = note.encode('utf-8')
print(bytes)
>>> b'\xf0\x9d\x85\x9e'
If i try to print the string directly i get
note = '\U0001d15e'
# bytes = note.encode('utf-8')
print(note)
Traceback (most recent call last):
File "c:\___\___\___\file.py", line 34, in <module>
print(note)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001d15e' in position 0: character maps to <undefined>
I am not sure what the problem is. I know that similar questions have been asked before, however the proposed solution did not work for me. Thank you for your help in advance :)
i am using python 3.10.4