Running a function periodically with asyncio Use the result returned by an async function Get the Current Date and Time with TimezoneĪn introduction to coroutines and event loops Use aiohttp to crawl webpages asynchronouslyīest open-source libraries to make HTTP requestsĬonvert Datetime to Timestamp and vice versa Generate a dummy list with N random elements Passing a list to a function as multiple arguments Replace unwanted words in a string with asterisksĬount the frequency of each word in a stringįind all occurrences of a value in a listĬount the occurrences of elements in a list Get hostname, domain, and protocol from a URL Get the filename and the file extension from a URL Remove all non-alphanumeric characters from a stringĬonvert a character to a code point and vice versa Remove one or many substrings from a string The modern Python regular expressions cheat sheetĬapitalize the first letter of each word in a stringĬompare 2 strings ignoring case sensitivity Generating a random float between min and maxįormat large numbers with comma separators Generate a random integer between min and max Just the state encoding is already a massive limitation: if you only used two-byte UTF8 sequences, you would not even be able to beat base64, even by using unassigned code points (each pair of bytes will use five bits on state encoding).Check if a string can be converted to a number Aside from being a variable-length encoding, UTF-8 wastes a lot of bits on state encoding (if you randomly index the data, you can instantly tell whether you are inside a multi-byte sequence by examining the current byte) and a lot of code points are just not assigned or will have weird display effects. I made a start at designing something that exploits UTF-8, but it really only pushes the limit to 6 encoding bits for 5 data bits (base64 uses 4 for 3 there is base85 that gets 5 for 4) and is quite complex. You really can’t save a lot by following the road you have in mind. I’ve considered this problem a fair bit in the past. Python accepts the string literals you’re generating.Ĭameron Simpson guess that the actual practical purpose for this is to embed binary data in JSON, which uses a very similar string format to Python’s string literals (but only using double quotes as delimiters). Trip through your encoding and back to the original bytes, and also that Problem? Maybe not, but you should consider it.Īlso, you will want to write some tests to check that things round Someone reading it aloud to another person or debugging an encoding So: should your encoding be visually clear to a human reader, eg to “i”, an “I”, an “l”, a “1”? A “0” or an “O”? And that’s without movingīeyond the ASCII Latin letters and Arabic numerals. Reading the text, and this can depend a lot on fonts too. The more characters you useīeyond a core set, the more visual ambiguity there can be to someone Get through many email systems with varying character sets and 8-bitĬleanliness but also to be human readable. However, keep in mind that base64 and the like are chosen not just to Or you could get very fancy, and run press on your data and Something very simple which escaped (eg with a backslash) just those 3 It suggests that you can possibly use any Unicode character except the This chapter describes how the lexical analyzer breaks a file into tokens. Input to the parser is a stream of tokens, generated by the lexical analyzer. Lexical analysisĪ Python program is read by a parser. The specification for a Python Unicode literal is here: Python documentation 2. You just want “Unicode text legal in a Python Note that UTF-8 is a binary encoding with no relationship to your I should have made that clearer.Īnd here’s the larger context. Surprisingly, it is really not about the bitzise to me, I actually careĪbout a visually compact representation of the data as a python unicode So please accept that I have that unusual need and don’t want something Larger undescribed problem which often has a better technical solution. In some transport, and that choosing how to encode depending on yourĪlso, very often, people ask for a specific technical approach to some Tired of the game: person asks question → person immediately has to justify why and gets lectured on how what they want is wrong.īarry’s explaining that the purpose of encodings is embedding the string I really do! I also appreciate, that you want to safe meįrom myself, that is very valiant of you! It’s just that I’m a bit Hi Barry, I appreciate that you took the time to read my question andĪnswer me.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |