Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Argument of the bool function

Reply
Thread Tools

Argument of the bool function

 
 
Grant Edwards
Guest
Posts: n/a
 
      04-10-2011
On 2011-04-09, Lie Ryan <(E-Mail Removed)> wrote:
> On 04/09/11 08:59, candide wrote:
>> Le 09/04/2011 00:03, Ethan Furman a ?crit :
>>
>>> > bool([x])


>> dir([object])


>> Not very meaningful, isn't it ?

>
> The error says it unambiguously, dir() does not take *keyword*
> arguments; instead dir() takes *positional* argument:
>
> dir("Explicit is better than implicit")


I think the point is that both cases are documented exactly the same.

--
Grant


 
Reply With Quote
 
 
 
 
rusi
Guest
Posts: n/a
 
      04-10-2011
On Apr 10, 8:35*am, Grant Edwards <(E-Mail Removed)> wrote:
> On 2011-04-09, Lie Ryan <(E-Mail Removed)> wrote:
>
> > On 04/09/11 08:59, candide wrote:
> >> Le 09/04/2011 00:03, Ethan Furman a ?crit :

>
> >>> *> bool([x])
> >> dir([object])
> >> Not very meaningful, isn't it ?

>
> > The error says it unambiguously, dir() does not take *keyword*
> > arguments; instead dir() takes *positional* argument:

>
> > * * dir("Explicit is better than implicit")

>
> I think the point is that both cases are documented exactly the same.


In what case(s) would a keyword arg to bool be reasonable?
 
Reply With Quote
 
 
 
 
Robert Kern
Guest
Posts: n/a
 
      04-10-2011
On 2011-04-09 23:15 , rusi wrote:
> On Apr 10, 8:35 am, Grant Edwards<(E-Mail Removed)> wrote:
>> On 2011-04-09, Lie Ryan<(E-Mail Removed)> wrote:
>>
>>> On 04/09/11 08:59, candide wrote:
>>>> Le 09/04/2011 00:03, Ethan Furman a ?crit :

>>
>>>>> > bool([x])
>>>> dir([object])
>>>> Not very meaningful, isn't it ?

>>
>>> The error says it unambiguously, dir() does not take *keyword*
>>> arguments; instead dir() takes *positional* argument:

>>
>>> dir("Explicit is better than implicit")

>>
>> I think the point is that both cases are documented exactly the same.

>
> In what case(s) would a keyword arg to bool be reasonable?


It's just an implementation detail. It's not worth the electrons wasted in this
thread already.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

 
Reply With Quote
 
candide
Guest
Posts: n/a
 
      04-10-2011
Le 08/04/2011 18:41, Benjamin Kaplan a écrit :

> bool(x=5) is just passing the value 5 as the argument "x" to the function.
>



Anyway, passing x as a keyword argument to the bool function appears to
be very rare : i did a regexp search for about 30000 source-code Python
files (among them official Python source-code, Django, Sphinx, Eric
source-code and many more sources of valuable Python code) and I didn't
find even one.
 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      04-10-2011
On Sun, Apr 10, 2011 at 10:54 PM, candide <(E-Mail Removed)> wrote:
> Anyway, passing x as a keyword argument to the bool function appears to be
> very rare : i did a regexp search for about 30000 source-code Python files
> (among them official Python source-code, Django, Sphinx, Eric source-code
> and many more sources of valuable Python code) and I didn't find even one.


Who would use keyword arguments with a function that takes only one arg anyway?

ChrisA
 
Reply With Quote
 
Mel
Guest
Posts: n/a
 
      04-10-2011
Chris Angelico wrote:

> Who would use keyword arguments with a function that takes only one arg
> anyway?


It's hard to imagine. Maybe somebody trying to generalize function calls
(trying to interpret some other language using a python program?)

# e.g. input winds up having the effect of ..
function = bool
name = 'x'
value = 'the well at the end of the world'
## ...
actions.append ((function, {name:value}))
## ...
for function, args in actions:
results.append (function (**args))

Not something I, for one, do every day. But regularity in a language is
good when you can get it, especially for abstract things like that.

I can sort of guess that `dir` was perhaps coded in C for speed and doesn't
spend time looking for complicated argument lists.

Python is a pragmatic language, so all the rules come pre-broken.


Mel.
 
Reply With Quote
 
Colin J. Williams
Guest
Posts: n/a
 
      04-10-2011
On 10-Apr-11 12:21 PM, Mel wrote:
> Chris Angelico wrote:
>
>> Who would use keyword arguments with a function that takes only one arg
>> anyway?

>
> It's hard to imagine. Maybe somebody trying to generalize function calls
> (trying to interpret some other language using a python program?)
>
> # e.g. input winds up having the effect of ..
> function = bool
> name = 'x'
> value = 'the well at the end of the world'
> ## ...
> actions.append ((function, {name:value}))
> ## ...
> for function, args in actions:
> results.append (function (**args))
>
> Not something I, for one, do every day. But regularity in a language is
> good when you can get it, especially for abstract things like that.
>
> I can sort of guess that `dir` was perhaps coded in C for speed and doesn't
> spend time looking for complicated argument lists.
>
> Python is a pragmatic language, so all the rules come pre-broken.
>
>
> Mel.

This thread has lasted 3 days so far.

I presume that it is agreed they the following is a satisfactory outcome:

*** Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit
(Intel)] on win32. ***
>>> bool(x=0)

False
>>> bool(x=1)

True
>>>


Colin W.

 
Reply With Quote
 
Ethan Furman
Guest
Posts: n/a
 
      04-11-2011
Mel wrote:
> Python is a pragmatic language, so all the rules come pre-broken.


+1 QOTW
 
Reply With Quote
 
Thomas Rachel
Guest
Posts: n/a
 
      04-25-2011
Am 10.04.2011 18:21, schrieb Mel:
> Chris Angelico wrote:
>
>> Who would use keyword arguments with a function that takes only one arg
>> anyway?

>
> It's hard to imagine. Maybe somebody trying to generalize function calls
> (trying to interpret some other language using a python program?)
>
> # e.g. input winds up having the effect of ..
> function = bool
> name = 'x'
> value = 'the well at the end of the world'
> ## ...
> actions.append ((function, {name:value}))
> ## ...
> for function, args in actions:
> results.append (function (**args))


Wrong structure.

Better do

function = bool
value = 'the well at the end of the world'
## ...
actions.append((function, (value,), {}))
## ...
for function, args, kwargs in actions:
results.append(function(*args, **kwargs))

or maybe even better (taking care for closures):

function = bool
value = 'the well at the end of the world'
## ...
actions.append(lambda val=value: function(val))
## ...
for function in actions:
results.append(function())


>
> Not something I, for one, do every day. But regularity in a language is
> good when you can get it, especially for abstract things like that.
>
> I can sort of guess that `dir` was perhaps coded in C for speed and doesn't
> spend time looking for complicated argument lists.
>
> Python is a pragmatic language, so all the rules come pre-broken.
>
>
> Mel.


 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      04-25-2011
On Tue, Apr 26, 2011 at 12:29 AM, Thomas Rachel
<(E-Mail Removed)>
wrote:
> for function in actions:
> * * results.append(function())


Can this become:

results = [function() for function in actions]

Chris Angelico
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable argument function as a parameter of a variable argument function AikidoGuy C Programming 11 11-21-2011 10:43 PM
function argument dependent on another function argument? Reckoner Python 11 01-19-2009 03:31 AM
error: passing `const Equal4' as `this' argument of `bool Equal4::operator()(int)' discards qualifiers Lycan. Mao.. C++ 4 03-04-2007 02:37 PM
Function pointers, variable argument functions calling other variable-argument functions (sort of) S?ren Gammelmark C Programming 1 01-07-2005 09:41 PM
How to pass variable argument list to another function w/ variable argument list? Ben Kial C Programming 1 11-15-2004 01:51 AM



Advertisments