Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to print UTF-8
#1
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
I think this should be working in 2 and 3

sometext = "André"
print("mytext: %s" % sometext)
More About Unicode in Python 2 and 3
Reply
#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().
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
(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?
Reply
#5
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
Quote:how to print UTF-8
print('UTF-8')
Just toying
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020