Python Forum
how to print UTF-8 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: how to print UTF-8 (/thread-12249.html)



how to print UTF-8 - Skaperen - Aug-16-2018

my string is already in UTF-8 form. that is, 1 to 6 byte codes (octets) in sequence per character and the codes are in range(256) (could have been in bytes but is in str). how do i tell the print function in Python3 and the print command in Python2 that the string is already in UTF-8 form? does converting it to bytes first, help to print it right? do i need to set environment variable LC_ALL to some value?


RE: how to print UTF-8 - Axel_Erfurt - Aug-16-2018

I think this should be working in 2 and 3

sometext = "André"
print("mytext: %s" % sometext)
More About Unicode in Python 2 and 3


RE: how to print UTF-8 - Skaperen - Aug-17-2018

that article did not cover UTF-8 at all, and did not convince me to stay with Python2/

but, i figured out that all i need to do is output UTF-8 via os.write().


RE: how to print UTF-8 - Axel_Erfurt - Aug-17-2018

(Aug-17-2018, 02:43 AM)Skaperen Wrote: but, i figured out that all i need to do is output UTF-8 via os.write().

Is not os.write() used to write content to files?


RE: how to print UTF-8 - Skaperen - Aug-17-2018

it depends on which file descriptor you write to. the process inherits file descriptors 0,1,2 from the shell that starts it. in the POSIX/Unix/Linux world, 0 is stdin, 1 is stdout, 2 is stderr. as i understand it, where Windows implements these functions it does it the same way. if you open "/dev/tty", you get a new file descriptor (3 or higher). open it for output and write to it and the output goes to the emulated terminal.


RE: how to print UTF-8 - Larz60+ - Aug-18-2018

Quote:how to print UTF-8
print('UTF-8')
Just toying