On 18.1.2019 19:16, Shakti Kumar wrote:
Hello people,
I noticed something weird (weird as per my current knowledge, though I know
its subjective) today.
Hi Kumar,
mock_req.get('').return_value = 'Hello'
Here you are calling mock_req -MagicMocks get-method with paramet
Shakti Kumar ezt írta (időpont: 2019. jan.
18., P, 18:18):
> Hello people,
> I noticed something weird (weird as per my current knowledge, though I know
> its subjective) today.
>
> sample.py file
>
> --
>
> import requests
> def random_testing():
> out = requests.get('www.cisco.com')
> a
Hello people,
I noticed something weird (weird as per my current knowledge, though I know
its subjective) today.
sample.py file
--
import requests
def random_testing():
out = requests.get('www.cisco.com')
a = out.json()
return a
testing.py file
--
@patch(*’*sample.requests')
def
On 30/05/18 06:51, Chris Angelico wrote:
On Wed, May 30, 2018 at 3:44 PM, MrMagoo2018 wrote:
Hello folks, imagine I have the code below and I am getting the "error" message
when attempting to print() the output of 'sw_report'.
Can you suggest which method I should use to retrieve this? Is that
On Wed, May 30, 2018 at 3:44 PM, MrMagoo2018 wrote:
> Hello folks, imagine I have the code below and I am getting the "error"
> message when attempting to print() the output of 'sw_report'.
> Can you suggest which method I should use to retrieve this? Is that a
> dictionary maybe?
>
> from arist
Hello folks, imagine I have the code below and I am getting the "error" message
when attempting to print() the output of 'sw_report'.
Can you suggest which method I should use to retrieve this? Is that a
dictionary maybe?
from arista import arista
m = arista()
m.authenticate ("user","password")
On Wed, Dec 31, 2008 at 10:54 AM, MRAB wrote:
> Occasionally someone posts here wanting to count items and solutions
> involving dict or defaultdict are suggested, and I think that a 'bag' class
> would be useful. The 'set' class was introduced first in a module, but it
> soon became a builtin. My
On Wed, Dec 31, 2008 at 10:49 AM, Steven D'Aprano
wrote:
> What set module?
Sorry I must have meant the collections module :)
> Adding a multi-set or bag class to the collections module would be a good
> idea though. Perhaps you should put in a feature request?
:) Perhaps I will.
cheers
James
James Mills wrote:
On Wed, Dec 31, 2008 at 10:22 AM, John Machin wrote:
(snip)
The "crawl through the shrubbery looking for evidence" approach
stumbles on the actual code:
Yes I found his implementation soon after :)
Not bad actually... I wonder why bag() isn't
shipped with the std lib - per
On Wed, 31 Dec 2008 10:29:14 +1000, James Mills wrote:
> On Wed, Dec 31, 2008 at 10:22 AM, John Machin
> wrote: (snip)
>
>> The "crawl through the shrubbery looking for evidence" approach
>> stumbles on the actual code:
>
> Yes I found his implementation soon after :) Not bad actually... I
> wo
On Wed, Dec 31, 2008 at 10:22 AM, John Machin wrote:
(snip)
> The "crawl through the shrubbery looking for evidence" approach
> stumbles on the actual code:
Yes I found his implementation soon after :)
Not bad actually... I wonder why bag() isn't
shipped with the std lib - perhaps in teh set
mod
On Dec 31, 10:58 am, "James Mills"
wrote:
> On Wed, Dec 31, 2008 at 9:15 AM, MRAB wrote:
>
> (snip)
>
> > A while back I posted a Python implementation of 'bag' (also called a
> > multiset). The code would then become something like:
>
> What complexity is this ?
The "armchair philosopher" appro
On Wed, Dec 31, 2008 at 9:15 AM, MRAB wrote:
(snip)
> A while back I posted a Python implementation of 'bag' (also called a
> multiset). The code would then become something like:
What complexity is this ?
cheers
James
--
http://mail.python.org/mailman/listinfo/python-list
James Mills wrote:
On Tue, Dec 30, 2008 at 7:10 PM, Roel Schroeven
wrote:
Hm, you just changed an O(n) algorithm to an O(n**2) algorithm. No big
deal for short strings, but try your solution on a string with length
1 and see the difference. On my computer the O(n) version takes
0.008 second
On Tue, Dec 30, 2008 at 7:10 PM, Roel Schroeven
wrote:
> Hm, you just changed an O(n) algorithm to an O(n**2) algorithm. No big
> deal for short strings, but try your solution on a string with length
> 1 and see the difference. On my computer the O(n) version takes
> 0.008 seconds, while your
James Mills schreef:
> Ross, the others have informed you that you are not
> actually incrementing the count. I'll assume you've
> fixed your function now :) ... I want to show you a far
> simpler way to do this which takes advantage of
> Python's list comprehensions and mappings (which are
> reall
On Dec 29, 8:02 pm, Steven D'Aprano wrote:
> On Mon, 29 Dec 2008 17:38:36 -0800, Ross wrote:
> > On Dec 29, 8:07 pm, Scott David Daniels wrote:
> >> Ross wrote:
> >> > ... Use get to write histogram more concisely. You should be able to
> >> > eliminate the if statement.
>
> >> > def histogram(s)
On Mon, 29 Dec 2008 17:38:36 -0800, Ross wrote:
> On Dec 29, 8:07 pm, Scott David Daniels wrote:
>> Ross wrote:
>> > ... Use get to write histogram more concisely. You should be able to
>> > eliminate the if statement.
>>
>> > def histogram(s):
>> > d = dict()
>> > for c in s:
>> >
On Tue, Dec 30, 2008 at 11:43 AM, James Mills
wrote:
> On Tue, Dec 30, 2008 at 11:38 AM, Ross wrote:
>> I realize the code isn't counting, but how am I to do this without
>> using an if statement as the problem instructs?
>
> I just gave you a hint :)
Ross:
This exercise is a simple exercise de
On Tue, Dec 30, 2008 at 11:38 AM, Ross wrote:
> I realize the code isn't counting, but how am I to do this without
> using an if statement as the problem instructs?
I just gave you a hint :)
cheers
James
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 29, 8:07 pm, Scott David Daniels wrote:
> Ross wrote:
> > ... Use get to write histogram more concisely. You should be able to
> > eliminate the if statement.
>
> > def histogram(s):
> > d = dict()
> > for c in s:
> > d[c]= d.get(c,0)
> > return d
>
> > This code returns
On Tue, Dec 30, 2008 at 11:32 AM, James Mills
wrote:
> Ross, the others have informed you that you are not
> actually incrementing the count. I'll assume you've
> fixed your function now :) ... I want to show you a far
> simpler way to do this which takes advantage of
> Python's list comprehension
On Tue, Dec 30, 2008 at 11:00 AM, Ross wrote:
> I am teaching myself Python by going through Allen Downing's "Think
> Python." I have come across what should be a simple exercise, but I am
> not getting the correct answer. Here's the exercise:
>
> Given:
>
> def histogram(s):
>d = dict()
>
Ross wrote:
... Use get to write histogram more concisely. You should be able to
eliminate the if statement.
def histogram(s):
d = dict()
for c in s:
d[c]= d.get(c,0)
return d
This code returns a dictionary of all the letters to any string s I
give it but
On Mon, 29 Dec 2008 17:00:31 -0800, Ross wrote:
> Here's my code:
>
> def histogram(s):
> d = dict()
> for c in s:
> d[c]= d.get(c,0)
> return d
>
> This code returns a dictionary of all the letters to any string s I give
> it but each corresponding value is incor
I am teaching myself Python by going through Allen Downing's "Think
Python." I have come across what should be a simple exercise, but I am
not getting the correct answer. Here's the exercise:
Given:
def histogram(s):
d = dict()
for c in s:
if c not in d:
d[c] = 1
On Feb 8, 4:24 pm, [EMAIL PROTECTED] wrote:
> > > val = BETTER foo THAN bar
>
> > > ;-)
>
> > > Cobol-strikes-back-ly yours,
>
> > > George
>
> > I use a ETL language/tool that actually has a function for this kind
> > of thing:
>
> > NulltoValue(value,defaultValue)
>
> > it returns defaultValue if
[EMAIL PROTECTED] writes:
> (would it help if I put lots of blank lines after this, so the disclaimer
> is out-of-sight/out-of-mind?)
Not really.
It would help far more if you could stop having this disclaimer appear
at all on this list (or any other list, really, but that's a matter
for those l
Carl Banks:
> I think booleans should be completely disjoint from all other types,
> as they are in Java. "and", "or", and "not" should accept only boolean
> operands and return only boolean results.
I'd like "or" and "and" (and "not") to return booleans only, to avoid
bugs and make their meanin
En Fri, 08 Feb 2008 13:24:19 -0200, <[EMAIL PROTECTED]>
escribió:
>
> Matt.
> (would it help if I put lots of blank lines after this, so the disclaimer
> is out-of-sight/out-of-mind?)
> --
> ie, from here on?
No, what would help is a line containing *exactly*
(dash)(dash)(space)(newline)
That
On Feb 8, 3:38 am, [EMAIL PROTECTED] wrote:
> Can't you just make a subclass of Boolean and add methods to the true/
> false, or am i running up a tree with a cat?
I'm not sure what point you were trying to make, but no you can't
subclass bool in Python as it is now; certainly it wouldn't be
possi
> > val = BETTER foo THAN bar
> >
> > ;-)
> >
> > Cobol-strikes-back-ly yours,
> >
> > George
>
> I use a ETL language/tool that actually has a function for this kind
> of thing:
>
> NulltoValue(value,defaultValue)
>
> it returns defaultValue if value is null otherwise value.
even Ksh has one
On Feb 7, 4:36 pm, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Feb 7, 4:25 pm, Steven D'Aprano <[EMAIL PROTECTED]
>
>
>
> cybersource.com.au> wrote:
> > On Thu, 07 Feb 2008 15:59:13 +0100, Wildemar Wildenburger wrote:
> > > Arnaud Delobelle wrote:
> > >> Personally, between
>
> > >> * foo if foo
On Feb 8, 8:23 am, Carl Banks <[EMAIL PROTECTED]> wrote:
> On Feb 7, 8:44 am, Steve Holden <[EMAIL PROTECTED]> wrote:
>
> > [EMAIL PROTECTED] wrote:
> > > I'd like to know what others think about it, about this anti-feature.
> > > What I can say is that other computer languages too think that boole
On Feb 7, 8:44 am, Steve Holden <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > I'd like to know what others think about it, about this anti-feature.
> > What I can say is that other computer languages too think that boolean
> > operations must return boolean values only, so I am not alon
En Thu, 07 Feb 2008 19:36:57 -0200, George Sakkis
<[EMAIL PROTECTED]> escribió:
> On Feb 7, 4:25 pm, Steven D'Aprano <[EMAIL PROTECTED]
> cybersource.com.au> wrote:
>> On Thu, 07 Feb 2008 15:59:13 +0100, Wildemar Wildenburger wrote:
>>
>> > val = foo rather than bar
>>
>> > If that is not clear
On Feb 7, 4:25 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Thu, 07 Feb 2008 15:59:13 +0100, Wildemar Wildenburger wrote:
> > Arnaud Delobelle wrote:
> >> Personally, between
>
> >> * foo if foo else bar
> >> * foo or bar
>
> >> I prefer the second. Maybe it could be spelt
"Denis Bilenko" <[EMAIL PROTECTED]> writes:
> I convinced that this
>
> line = self._buffer.get(self._bufindex)
> if line is None:
> self._bufindex += 1
> self._lineno += 1
> self._filelineno += 1
> return line
> line = self.readline()
I haven't looked
On Thu, 07 Feb 2008 15:59:13 +0100, Wildemar Wildenburger wrote:
> Arnaud Delobelle wrote:
>> Personally, between
>>
>> * foo if foo else bar
>> * foo or bar
>>
>> I prefer the second. Maybe it could be spelt
>>
>> * foo else bar ?
>>
> How about
>
> val = foo rather than bar
>
> If that is
On Feb 7, 12:15 pm, [EMAIL PROTECTED] wrote:
> On Feb 7, 11:01 am, "Denis Bilenko" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Steve Holden wrote:
> > > These versions differ with respect to treatment of blank lines, which
> > > indicates how easy it is to go astray in this kind of semantic
> > > optimiz
Wildemar Wildenburger wrote:
> Arnaud Delobelle wrote:
>> Personally, between
>>
>> * foo if foo else bar
>> * foo or bar
>>
>> I prefer the second. Maybe it could be spelt
>>
>> * foo else bar ?
>>
> How about
>
> val = foo rather than bar
>
> If that is not clear and obvios, I don't know what i
On Feb 7, 11:01 am, "Denis Bilenko" <[EMAIL PROTECTED]> wrote:
> Steve Holden wrote:
> > These versions differ with respect to treatment of blank lines, which
> > indicates how easy it is to go astray in this kind of semantic
> > optimization. Your example simply wouldn't work (though you could pa
Steve Holden wrote:
> These versions differ with respect to treatment of blank lines, which
> indicates how easy it is to go astray in this kind of semantic
> optimization. Your example simply wouldn't work (though you could patch
> it up using "if line is None". (despite the use of short-circuiti
Wildemar Wildenburger wrote:
> Arnaud Delobelle wrote:
>> Personally, between
>>
>> * foo if foo else bar
>> * foo or bar
>>
>> I prefer the second. Maybe it could be spelt
>>
>> * foo else bar ?
>>
> How about
>
> val = foo rather than bar
>
> If that is not clear and obvios, I don't know what i
Arnaud Delobelle wrote:
> Personally, between
>
> * foo if foo else bar
> * foo or bar
>
> I prefer the second. Maybe it could be spelt
>
> * foo else bar ?
>
How about
val = foo rather than bar
If that is not clear and obvios, I don't know what is. ;)
/W
--
http://mail.python.org/mailman/
Thomas Bellman a écrit :
> Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
>
(snip)
>> In Lisp (and IIRC), an empty list is false, anything else
>> is true.
>
> There seems to be a language name missing from the parenthesis.
Yes, sorry - I was thinking of OCaml and/or Haskell, but
Denis Bilenko wrote:
> Tim Golden wrote:
>
>> Dodging your question slightly (and at the risk of teaching
>> my grandmother to suck eggs) I sometimes use this idiom for
>> checking params. Obviously it only goes so far, but it's
>> fairly compact:
>
>>
>> import os, sys
>
>> if __name__ == '__m
[EMAIL PROTECTED] wrote:
> Steven D'Aprano:
>> With the greatest respect, I think that if you think the second example
>> "is more clear", you're completely bonkers. *grins*
>
It's amusing how often "with the greatest respect" is used to preface a
statement that clearly implies very little respec
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote:
> Not quite. In C and a couple other langages, int 0 is false, anything
> else is true.
Not just int, but all kinds of integers, as well as all kinds of
floating point types and all kinds of pointers, with the value 0
are considered false. And stru
[EMAIL PROTECTED] a écrit :
> Steven D'Aprano:
>> With the greatest respect, I think that if you think the second example
>> "is more clear", you're completely bonkers. *grins*
>
> No one is completely normal, I presume :-)
> I'd like to know what others think about it, about this anti-feature.
s
Denis Bilenko wrote:
> Raymond Hettinger wrote:
>> If positions 0 and 1 are optional, how do you expect to know whether
>> "path" is going to be at position 2? This problem doesn't exist with
>> dictionaries because the presence or absence of optional entries does
>> not affect the key reference t
On Feb 7, 8:20 am, [EMAIL PROTECTED] wrote:
> Paul Rubin:
>
> > I like the suggestion, except it should be
> > port = int(sys.argv.get(1, '8000'))
> > one could imagine your example going wrong in a protocol where 0 is
> > a valid port number.
>
> I think a high-level language like Python must
Steven D'Aprano:
> With the greatest respect, I think that if you think the second example
> "is more clear", you're completely bonkers. *grins*
No one is completely normal, I presume :-)
I'd like to know what others think about it, about this anti-feature.
What I can say is that other computer la
Tim Golden wrote:
> Dodging your question slightly (and at the risk of teaching
> my grandmother to suck eggs) I sometimes use this idiom for
> checking params. Obviously it only goes so far, but it's
> fairly compact:
>
> import os, sys
> if __name__ == '__main__':
> ARGS = None, "DEV"
> f
On Thu, 07 Feb 2008 00:20:52 -0800, bearophileHUGS wrote:
> I think a high-level language like Python must have boolean operators
> (or and not) that behave in a much more clean way, with a simpler
> semantics. That is they have to return only true or false. Otherwise
> they are just a source of b
Denis Bilenko wrote:
> Why does list have no 'get' method with exactly the same semantics as
> dict's get,
> that is "return an element if there is one, but do NOT raise
> an exception if there is not.":
>
> def get(self, item, default = None):
&g
[EMAIL PROTECTED] wrote:
> Paul Rubin:
>> I like the suggestion, except it should be
>> port = int(sys.argv.get(1, '8000'))
>> one could imagine your example going wrong in a protocol where 0 is
>> a valid port number.
>
> I think a high-level language like Python must have boolean operators
Paul Rubin:
> I like the suggestion, except it should be
> port = int(sys.argv.get(1, '8000'))
> one could imagine your example going wrong in a protocol where 0 is
> a valid port number.
I think a high-level language like Python must have boolean operators
(or and not) that behave in a much
[Denis Bilenko]
> Why does list have no 'get' method with exactly the same semantics as
> dict's get,
> that is "return an element if there is one, but do NOT raise
> an exception if there is not.":
. . .
> It is often desirable, for example, when one
"Denis Bilenko" <[EMAIL PROTECTED]> writes:
> port = sys.argv.get(1) or 8000
I like the suggestion, except it should be
port = int(sys.argv.get(1, '8000'))
one could imagine your example going wrong in a protocol where 0 is
a valid port number.
--
http://mail.python.org/mailman/listinf
Why does list have no 'get' method with exactly the same semantics as
dict's get,
that is "return an element if there is one, but do NOT raise
an exception if there is not.":
def get(self, item, default = None):
try:
return self[item]
Chad wrote:
> On Apr 12, 5:03 pm, James Stroud <[EMAIL PROTECTED]> wrote:
>> James Stroud wrote:
>>> Chad wrote:
I have a simple little program that brings up asks the user to enter a
note, then is supposed to place that note into a text file when the
user hits the submit button. Ho
On Apr 12, 5:03 pm, James Stroud <[EMAIL PROTECTED]> wrote:
> James Stroud wrote:
> > Chad wrote:
>
> >> I have a simple little program that brings up asks the user to enter a
> >> note, then is supposed to place that note into a text file when the
> >> user hits the submit button. However, when t
James Stroud wrote:
> Chad wrote:
>
>> I have a simple little program that brings up asks the user to enter a
>> note, then is supposed to place that note into a text file when the
>> user hits the submit button. However, when the user hits the submit
>> button, absolutely nothing happens. IDLE
Chad wrote:
> I have a simple little program that brings up asks the user to enter a
> note, then is supposed to place that note into a text file when the
> user hits the submit button. However, when the user hits the submit
> button, absolutely nothing happens. IDLE doesn't give an error
> messa
Chad wrote:
> I have a simple little program that brings up asks the user to enter a
> note, then is supposed to place that note into a text file when the
> user hits the submit button. However, when the user hits the submit
> button, absolutely nothing happens. IDLE doesn't give an error
> messa
I have a simple little program that brings up asks the user to enter a
note, then is supposed to place that note into a text file when the
user hits the submit button. However, when the user hits the submit
button, absolutely nothing happens. IDLE doesn't give an error
message and the note is not
Bengt Richter wrote:
> then there's always
>
>if 'x' in d: value = d['x']
>else: value = bsf()
>
> or
>
>try: value = d['x']
>except KeyError: value = bsf()
>
Its worth remembering that the first of those two suggestions is also
faster than using get, so you aren't losing on
On Fri, 11 Mar 2005 04:12:19 -0500, Steve Holden <[EMAIL PROTECTED]> wrote:
>Terry Reedy wrote:
>> "Skip Montanaro" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>>
>>> value = d.get('x') or bsf()
>>>
>>>Of course, this bsf() will get called if d['x'] evaluates to false, not
Terry Reedy wrote:
"Skip Montanaro" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
value = d.get('x') or bsf()
Of course, this bsf() will get called if d['x'] evaluates to false, not
just
None,
value = (d.get('x') is not None) or bsf() #??
Unfortunately this will set value to Tru
"Skip Montanaro" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>value = d.get('x') or bsf()
>
> Of course, this bsf() will get called if d['x'] evaluates to false, not
> just
> None,
value = (d.get('x') is not None) or bsf() #??
tjr
--
http://mail.python.org/mailman/listi
Dave> In this snippet:
Dave> d = {'x': 1}
Dave> value = d.get('x', bigscaryfunction())
Dave> the bigscaryfunction is always called, even though 'x' is a valid
Dave> key.
I sometimes use
value = d.get('x') or bsf()
Of course, this bsf() will get called if d['x'] evaluat
untested
def my_getter(m, i, f):
try:
return m[i]
except (KeyError, IndexError):
return f()
my_getter(d, 'x', bigscaryfunction)
my_getter(d, 'y', lambda: scaryinlineexpresion)
pgp04VRKFqQL1.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python
Dave Opstad wrote:
In this snippet:
d = {'x': 1}
value = d.get('x', bigscaryfunction())
the bigscaryfunction is always called, even though 'x' is a valid key.
Is there a "short-circuit" version of get that doesn't evaluate the
second argument if the first is a valid key? For now I'll code around
Bill Mill wrote:
On 9 Mar 2005 10:05:21 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
Maybe this can help:
value = d.get('x', lambda: bigscaryfunction())
def test(): print 'gbye'
...
d = {}
z = d.get('x', lambda: test())
z
at 0x008D6870>
So this seems to be merely an obfuscation of:
z = d.g
Dave Opstad wrote:
> In this snippet:
>
> d = {'x': 1}
> value = d.get('x', bigscaryfunction())
>
> the bigscaryfunction is always called, even though 'x' is a valid key.
> Is there a "short-circuit" version of get that doesn't evaluate the
> second argument if the first is a valid key? For now
F. Petitjean wrote:
Le Wed, 09 Mar 2005 09:45:41 -0800, Dave Opstad a écrit :
Is there a "short-circuit" version of get that doesn't evaluate the
second argument if the first is a valid key? For now I'll code around
it, but this behavior surprised me a bit...
def scary():
print "scary called"
On 09 Mar 2005 18:13:01 GMT, F. Petitjean <[EMAIL PROTECTED]> wrote:
> Le Wed, 09 Mar 2005 09:45:41 -0800, Dave Opstad a écrit :
> > In this snippet:
> >
> > d = {'x': 1}
> > value = d.get('x', bigscaryfunction())
> >
> > the bigscaryfunction is always called, even though 'x' is a valid key.
> > Is
On 9 Mar 2005 10:05:21 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Maybe this can help:
>
> value = d.get('x', lambda: bigscaryfunction())
>>> def test(): print 'gbye'
...
>>> d = {}
>>> z = d.get('x', lambda: test())
>>> z
at 0x008D6870>
So this seems to be merely an obfuscation of:
Le Wed, 09 Mar 2005 09:45:41 -0800, Dave Opstad a écrit :
> In this snippet:
>
> d = {'x': 1}
> value = d.get('x', bigscaryfunction())
>
> the bigscaryfunction is always called, even though 'x' is a valid key.
> Is there a "short-circuit" version of get that doesn't evaluate the
> second argume
Maybe this can help:
value = d.get('x', lambda: bigscaryfunction())
Bearophile
--
http://mail.python.org/mailman/listinfo/python-list
Dave,
On Wed, 09 Mar 2005 09:45:41 -0800, Dave Opstad <[EMAIL PROTECTED]> wrote:
> In this snippet:
>
> d = {'x': 1}
> value = d.get('x', bigscaryfunction())
>
> the bigscaryfunction is always called, even though 'x' is a valid key.
> Is there a "short-circuit" version of get that doesn't evalua
Dave Opstad wrote:
In this snippet:
d = {'x': 1}
value = d.get('x', bigscaryfunction())
the bigscaryfunction is always called, even though 'x' is a valid key.
Is there a "short-circuit" version of get that doesn't evaluate the
second argument if the first is a valid key? For now I'll code around
In this snippet:
d = {'x': 1}
value = d.get('x', bigscaryfunction())
the bigscaryfunction is always called, even though 'x' is a valid key.
Is there a "short-circuit" version of get that doesn't evaluate the
second argument if the first is a valid key? For now I'll code around
it, but this beh
84 matches
Mail list logo