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


Messages In This Thread
byte types - by Skaperen - Oct-31-2018, 10:44 PM
RE: byte types - by wavic - Nov-01-2018, 05:03 AM
RE: byte types - by Gribouillis - Nov-01-2018, 09:18 AM
RE: byte types - by Skaperen - Nov-01-2018, 06:22 PM
RE: byte types - by Gribouillis - Nov-01-2018, 08:08 PM
RE: byte types - by Skaperen - Nov-02-2018, 12:05 AM
RE: byte types - by Gribouillis - Nov-02-2018, 05:45 AM
RE: byte types - by Skaperen - Nov-02-2018, 02:48 PM
RE: byte types - by wavic - Nov-02-2018, 06:06 PM
RE: byte types - by Skaperen - Nov-04-2018, 09:32 PM
RE: byte types - by ichabod801 - Nov-05-2018, 02:24 AM
RE: byte types - by Skaperen - Nov-06-2018, 12:55 AM
RE: byte types - by wavic - Nov-05-2018, 07:58 AM
RE: byte types - by Gribouillis - Nov-06-2018, 08:01 AM
RE: byte types - by Skaperen - Nov-07-2018, 04:03 AM
RE: byte types - by Gribouillis - Nov-07-2018, 09:19 PM
RE: byte types - by Skaperen - Nov-07-2018, 09:26 PM

Forum Jump:

User Panel Messages

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