Python Forum
encoding control characters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
encoding control characters
#3
(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.
Reply


Messages In This Thread
encoding control characters - by Skaperen - Jan-25-2018, 04:02 AM
RE: encoding control characters - by sparkz_alot - Jan-25-2018, 02:30 PM
RE: encoding control characters - by Skaperen - Jan-26-2018, 07:03 AM
RE: encoding control characters - by sparkz_alot - Jan-26-2018, 03:08 PM
RE: encoding control characters - by Skaperen - Jan-27-2018, 04:03 AM
RE: encoding control characters - by sparkz_alot - Jan-27-2018, 02:18 PM
RE: encoding control characters - by Skaperen - Jan-28-2018, 02:30 AM

Forum Jump:

User Panel Messages

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