Fredrik Lundh wrote:
> Stephen Eilert wrote:
>
>> I do think that, if it is faster, Python should translate
>> "x.has_key(y)" to "y in x".
>
> http://svn.python.org/view/sandbox/trunk/2to3/fix_has_key.py?view=markup
Seems to have moved to here:
http://svn.python.org/view/sandbox/trunk/2to3/fixes
On Fri, 08 Dec 2006 17:42:56 +0100, Daniel Dittmar wrote:
> Marc 'BlackJack' Rintsch wrote:
>> If ``in`` shouldn't work with dictionaries, either `__contains__()` must
>> be implemented to throw an exception or dictionaries shouldn't be iterable.
>
> I agree completely (in the sense that dictiona
Ben Finney escreveu:
> "Stephen Eilert" <[EMAIL PROTECTED]> writes:
>
> > Is there a list somewhere listing those not-so-obvious-idioms?
>
> They're only not-so-obvious to those who learn one version of Python
> and then ignore release notes on future versions. The "k in some_dict"
> was a wonder
Daniel Dittmar wrote:
> I agree completely (in the sense that dictionaries shouldn't be iterable
> directly). Probably even more strongly, at least every time I see some
> code where someone iterates over the keys, only to use the key to look
> up the value (instead if using iteritms).
so? th
Marc 'BlackJack' Rintsch wrote:
> If ``in`` shouldn't work with dictionaries, either `__contains__()` must
> be implemented to throw an exception or dictionaries shouldn't be iterable.
I agree completely (in the sense that dictionaries shouldn't be iterable
directly). Probably even more strongly,
In <[EMAIL PROTECTED]>, Daniel Dittmar wrote:
> John Machin wrote:
>> No it doesn't look wrong to anyone who has read the docs on
>> sys.modules.
>
> My point was really that there is no obvious implementation for 'in' on
> dictionaries, so it should have been left out. And that GvR thought so
John Machin wrote:
> No it doesn't look wrong to anyone who has read the docs on
> sys.modules.
My point was really that there is no obvious implementation for 'in' on
dictionaries, so it should have been left out. And that GvR thought so
for quite some time as well (until he got mixed up with
Steven D'Aprano wrote:
> On Thu, 07 Dec 2006 13:52:33 -0800, George Sakkis wrote:
>
> > I'm surprized that none of these pages mentions the incompatible type
> > comparison gotcha:
> >
> 5 < "4"
> > True
> >
> > I'm sure this has bitten many folks, particularly (ex) Perl'ers.
>
> Why is this
At Thursday 7/12/2006 19:45, Steven D'Aprano wrote:
> I'm surprized that none of these pages mentions the incompatible type
> comparison gotcha:
>
5 < "4"
> True
>
> I'm sure this has bitten many folks, particularly (ex) Perl'ers.
Why is this a gotcha?
I can't speak for others, but except
"Stephen Eilert" <[EMAIL PROTECTED]> writes:
> Is there a list somewhere listing those not-so-obvious-idioms?
They're only not-so-obvious to those who learn one version of Python
and then ignore release notes on future versions. The "k in some_dict"
was a wonderful thing to read in the release no
On Thu, 07 Dec 2006 13:52:33 -0800, George Sakkis wrote:
> I'm surprized that none of these pages mentions the incompatible type
> comparison gotcha:
>
5 < "4"
> True
>
> I'm sure this has bitten many folks, particularly (ex) Perl'ers.
Why is this a gotcha?
I can't speak for others, but
Danny Colligan wrote:
> > Is there a list somewhere listing those not-so-obvious-idioms?
>
> I don't know about lists of not-so-obvious idioms, but here's some
> gotchas (there may be some overlap with what you're asking about):
>
> http://zephyrfalcon.org/labs/python_pitfalls.html
> http://www.fer
Daniel Dittmar wrote:
> Duncan Booth wrote:
> > In this case, dict objects used to not support the 'in' operator, but at
> > some point it was added. I believe it wasn't there originally because Guido
> > wasn't sure whether people would expect it should match keys or keys and
> > values.
>
> And
> Is there a list somewhere listing those not-so-obvious-idioms?
I don't know about lists of not-so-obvious idioms, but here's some
gotchas (there may be some overlap with what you're asking about):
http://zephyrfalcon.org/labs/python_pitfalls.html
http://www.ferg.org/projects/python_gotchas.html
Stephen Eilert wrote:
> I do think that, if it is faster, Python should translate
> "x.has_key(y)" to "y in x".
http://svn.python.org/view/sandbox/trunk/2to3/fix_has_key.py?view=markup
--
http://mail.python.org/mailman/listinfo/python-list
Duncan Booth escreveu:
>
> >
> > Is there a list somewhere listing those not-so-obvious-idioms? I've
> > seen some in this thread (like the replacement for .startswith).
> >
> The release notes for each new version. Unfortunately the rest of the
> documentation sometimes lags behind the release n
Duncan Booth wrote:
> In this case, dict objects used to not support the 'in' operator, but at
> some point it was added. I believe it wasn't there originally because Guido
> wasn't sure whether people would expect it should match keys or keys and
> values.
And he was right:
import sys
'sys' i
"Stephen Eilert" <[EMAIL PROTECTED]> wrote:
> I've always used has_key(), thinking it was the only way to do it.
> Given that Python says that "There Should Be Only One Way to Do It", I
> didn't bother searching for alternatives.
The full quote is actually:
There should be one-- and pref
On Thu, 07 Dec 2006 04:08:18 -0800, Stephen Eilert wrote:
> Given that Python says that "There Should Be Only One Way to Do It",
Python says no such thing.
Perhaps you should run "import this" at the prompt, and read _carefully_
and take note of the difference between the Zen of Python and what
Stephen Eilert wrote:
> Hendrik van Rooyen escreveu:
>
>> <[EMAIL PROTECTED]> wrote:
>>
>> > Peter> Bjoern Schliessmann wrote:
>> > >> Wouldn't be "if k in d.keys()" be the exact replacement?
>> >
>> > Peter> No, 'k in d' is equivalent to 'd.has_key(k)', only with less
>> > Peter>
Hendrik van Rooyen escreveu:
> <[EMAIL PROTECTED]> wrote:
>
> > Peter> Bjoern Schliessmann wrote:
> > >> Wouldn't be "if k in d.keys()" be the exact replacement?
> >
> > Peter> No, 'k in d' is equivalent to 'd.has_key(k)', only with less
> > Peter> (constant) overhead for the func
21 matches
Mail list logo