Python Forum
is this character printable?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
is this character printable?
#1
is this character printable?

i found a place where Python is making this decision, probably from a Unicode database. the repr() function, when given a raw character that cannot be printed, returns a string with an octal escape sequence for the code point value of that character. but if it is printable, it returns the same raw character. in both cases it puts single quotes before and after what it has decided to return.

this can be used to decide to print, or not, various Unicode characters. the way i do it is to check the length repr() returns for each single character. so i do code like len(repr(ch))<4 to make the decision to print the character or a blank in its place,
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
(Aug-15-2018, 05:34 AM)Skaperen Wrote: is this character printable?

Memory from the distant past: "don't open it, don't open - it's Pandora's box" (this is based on personal experience on this subject)

It is believed that Socrates have once said: "wisdom starts with definition of term". Term "printable character" needs to be defined and very precisely.

What is printable character? Does printable character equal to graphical character as defined in ISO 8859 and Unicode: any character intended to be written, printed, or otherwise displayed in a form that can be read by humans?

What about space (there is split opinion)? If space is printable character what about all other Unicode whitespaces (they display space)? What about non-spacing graphical characters which occupy previous characters space (meaning that printable character does not need to occupy any 'own' space)?

Is it 'printable' printable or 'output' printable? Does printable implies that character can be always printed in whatever environment? What about end-user who doesn't have necessary fonts (for example some Asian ones) installed. Does it mean that character is still printable?

But where are the questions there is an answer. To be consistent with the rest of the world there is always:

>>> help(str.isprintable)
Help on method_descriptor:

isprintable(self, /)
    Return True if the string is printable, False otherwise.
    
    A string is printable if all of its characters are considered printable in
    repr() or if it is empty.
(END)
One can rely on Python's "characters are considered printable" and hope that other pythonistas do the same.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
to include space the definition for this case is a character for which there exits a definition in the character code space involved (as opposed to those definitions that might leave space).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

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