[Python-ideas] __len__() for map()

E. Madison Bray erik.m.bray at gmail.com
Thu Nov 29 05:37:19 EST 2018


On Wed, Nov 28, 2018 at 11:04 PM Steven D'Aprano <steve at pearwood.info> wrote:
>
> On Wed, Nov 28, 2018 at 05:37:39PM +0100, Anders Hovmöller wrote:
> >
> >
> > > I just mentioned that porting effort for background.  I still believe
> > > that the actual proposal of making the arguments to a map(...) call
> > > accessible from Python as attributes of the map object (ditto filter,
> > > zip, etc.) is useful in its own right, rather than just having this
> > > completely opaque iterator.
> >
> > +1.  Throwing away information is almost always a bad idea.
>
> "Almost always"? Let's take this seriously, and think about the
> consequences if we actually believed that. If I created a series of
> integers:
>
> a = 23
> b = 0x17
> c = 0o27
> d = 0b10111
> e = int('1b', 12)
>
> your assertion would say it is a bad idea to throw away the information
> about how they were created, and hence we ought to treat all five values
> as distinct and distinguishable. So much for the small integer cache...

Not to go too off-topic but I don't think this is a great example
either.  Although as a practical consideration I agree Python
shouldn't preserve the base representation from which an integer were
created I often *wish* it would.  It's useful information to have.
There's nothing I hate more than doing hex arithmetic in Python and
having it print out decimal results, then having to wrap everything in
hex(...) before displaying.  Base representation is still meaningful,
often useful information.


More information about the Python-ideas mailing list