Python Forum

Full Version: how to print UTF-8
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
I think this should be working in 2 and 3

sometext = "André"
print("mytext: %s" % sometext)
More About Unicode in Python 2 and 3
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().
(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?
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.
Quote:how to print UTF-8
print('UTF-8')
Just toying