Nov-04-2018, 09:32 PM
(Nov-02-2018, 06:06 PM)wavic Wrote: A custom class with a __len__ method will be good enough. It can return whatever you want and calling len(instance)
could return the number of words, bytes, bits, rows, tables, stars, threes, people, cats, dogs, etc.
but, what if you have read in a line from a file using os.read() or by some other means ended up with data in a bytes or bytearray type, or have a list or tuple of the byte code numbers as ints, and want to know the number of utf-8 encoded characters, or want to know the uncompressed size of th original data that was compressed into that file? __len__() for existing types/classses does not give that (so len() does not, either).
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.