Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
byte types
#13
(Nov-05-2018, 02:24 AM)ichabod801 Wrote:
(Nov-04-2018, 09:32 PM)Skaperen Wrote: __len__() for existing types/classses does not give that (so len() does not, either).

That's why wavic said to create a custom class, not use one of the existing types. Then you can define __len__ to handle all of that stuff, and then len() will handle it for you.
the whole point about clen() is that any type (that could contain utf-8) which might be provided to a function (that needs to know how many utf-8 characters are in it) that calls clen() so clen() needs to be a single name that handles many types (all types that make sense for it ... all types that can contain utf-8).

it's just like len() except that len() gets to have a method (__len()__) in each type it can handle.

so basically, to implement clen() as versatile as len(), which is a reasonable goal, you need to add it to python itself (e.g. to existing types).

advise to create a custom type misses the mark by a kilometer.

post #1 is about how to work better at check types in a way that visibly suggests it is supporting multiple types. i believe this thread has degraded because of the agenda against handling multiple types. but i am wondering where this agenda originates. i suspect it is from python having the weakness of being unable to allow "user code" supporting dynamic typing the same way python itself can do, which can be solved by allowing "user code" to add methods to existing types (syntactically easy enough by setting attributes on types).
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