Jan-26-2018, 07:03 AM
(Jan-25-2018, 02:30 PM)sparkz_alot Wrote: Since the first 127 characters of ascii and unicode are the same, could you not simply use the unicode, i.e.: print('\u0007')
(for Alert Ctl-G)?
or even
print('\U00000007')
i guess i should add all these unicode sequences to both of my decode and encode functions. what i was looking for is an already existing implementation to see how they handle the case where many different sequences can be decoded to the same control character. the decode function is a non-issue since it can simply support every possible sequence, such as '\r' or '^m' or '\015' or '\d013' or '\o015' or '\x0d' or 'X0D' for carriage return decoding. but for encoding, which produces the sequence, which, of generally many possibilities, is to be produced? i am wanting to get an idea how people expect to handle this. i've already started writing code. for now my encode_control() function has a named option method= to select a method, if the default is not desired.
Python's repr() and ascii() functions are limited implementations that give this kind of output. for carriage return it always returns '\r' and has no means to choose an alternative. they are "limited" as in not supporting '\a' and '\b' and '\v' and '\f' even though literal string parsing does.
try
repr('\a\b\t\n\v\f\r')
and see that.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.