Hi!
it is interesting that I found this syntax error:
>>a = {} str('sdfd', **a,)
File "<stdin>", line 1
str('sdfd', **a,)
^
SyntaxError: invalid syntax
I just wonder is it intentional or by-product (bug or feature)?
(The behaviour makes sense, of course... I tend to leave commas when I
expect a list to be added to (i.e. almost always ;-)))
Regards,
Roman 7 1289
Roman,
According to the Python call syntax definition
( http://docs.python.org/ref/calls.html) commas should be allowed, so it
seems like a minor bug. Here are the lines in question:
-----http://docs.python.org/ref/calls.html-----------
call ::= primary "(" [argument_list [","]] ")"
argument_list::=positional_arguments ["," keyword_arguments] ["," "*"
expression] ["," "**" expression]
| keyword_arguments ["," "*" expression] ["," "**" expression]
| "*" expression ["," "**" expression]
| "**" expression
----------------------------------------------------------
If you notice in the 'call' definition, no matter what the
'argument_list' is, it can be followed by an optional ',' right before
the closing ')'. Your code is a counterexample to this. Here is a more
exhaustive example:
--------------------------------------------------------
>>def f(a,b):
.... pass
....
>>f(1,2) f(1,2,) f(1,*[2]) f(1,*[2],)
File "<stdin>", line 1
f(1,*[2],)
^
SyntaxError: invalid syntax
>>f(1,**{'b':2}) f(1,**{'b':2},)
File "<stdin>", line 1
f(1,**{'b':2},)
^
SyntaxError: invalid syntax
>>f(*[1,2]) f(*[1,2],)
File "<stdin>", line 1
f(*[1,2],)
^
SyntaxError: invalid syntax
>>f(**{'a':1,'b':2}) f(**{'a':1,'b':2},)
File "<stdin>", line 1
f(**{'a':1,'b':2},)
^
SyntaxError: invalid syntax
>>> f(1,b=2) f(1,b=2,) f(a=1,b=2,)
-----------------------------------------------------
Anybody else knows more about this?
/invoking the spirit of GvR... ;-)
Nick Vatamaniuc
Roman Susi wrote:
Hi!
it is interesting that I found this syntax error:
>a = {} str('sdfd', **a,)
File "<stdin>", line 1
str('sdfd', **a,)
^
SyntaxError: invalid syntax
I just wonder is it intentional or by-product (bug or feature)?
(The behaviour makes sense, of course... I tend to leave commas when I
expect a list to be added to (i.e. almost always ;-)))
Regards,
Roman
Nick Vatamaniuc wrote:
Roman,
According to the Python call syntax definition
(http://docs.python.org/ref/calls.html) commas should be allowed, so it
seems like a minor bug. Here are the lines in question:
-----http://docs.python.org/ref/calls.html-----------
call ::= primary "(" [argument_list [","]] ")"
argument_list::=positional_arguments ["," keyword_arguments] ["," "*"
expression] ["," "**" expression]
| keyword_arguments ["," "*" expression] ["," "**" expression]
| "*" expression ["," "**" expression]
| "**" expression
----------------------------------------------------------
If you notice in the 'call' definition, no matter what the
'argument_list' is, it can be followed by an optional ',' right before
the closing ')'. Your code is a counterexample to this. Here is a more
exhaustive example:
--------------------------------------------------------
Actually, in the real BNF it's not allowed: http://svn.python.org/view/python/tr...09&view=markup
parameters: '(' [varargslist] ')'
varargslist: ((fpdef ['=' test] ',')*
('*' NAME [',' '**' NAME] | '**' NAME) |
fpdef ['=' test] (',' fpdef ['=' test])* [','])
fpdef: NAME | '(' fplist ')'
True, that is why it behaves the way it does, but which way is the
correct way? i.e. does the code need updating or the documentation?
-Nick V. ol*****@verizon.net wrote:
Nick Vatamaniuc wrote:
Roman,
According to the Python call syntax definition
(http://docs.python.org/ref/calls.html) commas should be allowed, so it
seems like a minor bug. Here are the lines in question:
-----http://docs.python.org/ref/calls.html-----------
call ::= primary "(" [argument_list [","]] ")"
argument_list::=positional_arguments ["," keyword_arguments] ["," "*"
expression] ["," "**" expression]
| keyword_arguments ["," "*" expression] ["," "**" expression]
| "*" expression ["," "**" expression]
| "**" expression
----------------------------------------------------------
If you notice in the 'call' definition, no matter what the
'argument_list' is, it can be followed by an optional ',' right before
the closing ')'. Your code is a counterexample to this. Here is a more
exhaustive example:
--------------------------------------------------------
Actually, in the real BNF it's not allowed:
http://svn.python.org/view/python/tr...09&view=markup
parameters: '(' [varargslist] ')'
varargslist: ((fpdef ['=' test] ',')*
('*' NAME [',' '**' NAME] | '**' NAME) |
fpdef ['=' test] (',' fpdef ['=' test])* [','])
fpdef: NAME | '(' fplist ')'
"Nick Vatamaniuc" <va******@gmail.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
True, that is why it behaves the way it does, but which way is the
correct way? i.e. does the code need updating or the documentation?
I think the doc.
Nick Vatamaniuc wrote:
>True, that is why it behaves the way it does, but which way is the correct way? i.e. does the code need updating or the documentation?
Perhaps, someone can make a bug report... IMHO, docs are wrong.
-Roman
>-Nick V.
ol*****@verizon.net wrote:
>>Nick Vatamaniuc wrote:
>>>Roman,
According to the Python call syntax definition (http://docs.python.org/ref/calls.html) commas should be allowed, so it seems like a minor bug. Here are the lines in question: -----http://docs.python.org/ref/calls.html----------- call ::= primary "(" [argument_list [","]] ")" argument_list::=positional_arguments ["," keyword_arguments] ["," "*" expression] ["," "**" expression] | keyword_arguments ["," "*" expression] ["," "**" expression] | "*" expression ["," "**" expression] | "**" expression ---------------------------------------------------------- If you notice in the 'call' definition, no matter what the 'argument_list' is, it can be followed by an optional ',' right before the closing ')'. Your code is a counterexample to this. Here is a more exhaustive example: --------------------------------------------------------
Actually, in the real BNF it's not allowed:
http://svn.python.org/view/python/tr...09&view=markup
parameters: '(' [varargslist] ')' varargslist: ((fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME) | fpdef ['=' test] (',' fpdef ['=' test])* [',']) fpdef: NAME | '(' fplist ')'
Roman,
The way I see it, it could be either way. In other words if I can
write f(1,2,3) and f(1,2,3,) I should also be able to write
f(1,*[2,3],). It is a really small detail but there sould be some
consistency. Either no extra commas for all kinds of argument types or
extra commas for _all_ of them. It seems though also that if it is
possible to do it with lists, tuples and dictionaries, it should also
be possible to do it with argument lists. In other words if (1,2,3,)
makes sense so should func(1,2,3,) even when written as
func(1,2,*[3],).
Well you are the one who discovered this so you shoud be the one
submitting the bug report! Here is PEP 3 page with the guidelines for
bug reporting: http://www.python.org/dev/peps/pep-0003/
Just mark it as a very low priority since it is more of a cosmetic bug
than a serious showstopper.
-Nick V
Roman Susi wrote:
Nick Vatamaniuc wrote:
True, that is why it behaves the way it does, but which way is the
correct way? i.e. does the code need updating or the documentation?
Perhaps, someone can make a bug report... IMHO, docs are wrong.
-Roman
-Nick V.
ol*****@verizon.net wrote:
>Nick Vatamaniuc wrote:
Roman,
According to the Python call syntax definition (http://docs.python.org/ref/calls.html) commas should be allowed, so it seems like a minor bug. Here are the lines in question: -----http://docs.python.org/ref/calls.html----------- call ::= primary "(" [argument_list [","]] ")" argument_list::=positional_arguments ["," keyword_arguments] ["," "*" expression] ["," "**" expression] | keyword_arguments ["," "*" expression] ["," "**" expression] | "*" expression ["," "**" expression] | "**" expression ---------------------------------------------------------- If you notice in the 'call' definition, no matter what the 'argument_list' is, it can be followed by an optional ',' right before the closing ')'. Your code is a counterexample to this. Here is a more exhaustive example: --------------------------------------------------------
Actually, in the real BNF it's not allowed:
http://svn.python.org/view/python/tr...09&view=markup
parameters: '(' [varargslist] ')' varargslist: ((fpdef ['=' test] ',')*
('*' NAME [',' '**' NAME] | '**' NAME) |
fpdef ['=' test] (',' fpdef ['=' test])* [',']) fpdef: NAME | '(' fplist ')'
Dennis,
You make a good point, that is what I though first. Semantically I
thought a comma after **kw as in ..., **kw,) doesn't make sense because
there is nothing that could follow **kw except the ')'. But then trying
some other cases (see the previous posts for my examples) I noticed
that commas aren't allowed after *pos_args also. For example if ....,
*pos_args,) would be an error BUT stuff could follow *pos_args and that
could be **kw as in ..., *pos_args,**kw).
In other words the behavior is not consistent. So it seems that 3
things could happen with this:
1) Not allow commas after **kw only. Allow them in any other case,
because semantically 'stuff' could possibly follow.
2) Don't allow extra commas for all the argument lists. In other words
f(1,2,) or f(a=1,b=2,) would be an error. But then do we want argument
lists to be consistent with tuples as far as syntax goes?
3) Allow trailing commas after all kinds of arguments in the argument
lists. This is what the documentation describes at the moment. I think
this is more sensible. I understand that argument lists and tuples are
not the same, but it would be nice to have a _syntactic_ consistency,
as opposed to 'a surprise'. As in t=(1,2,3,) f(1,2,3,) f(1,*[2,3],)
and f(1,*[2],**{'c':3},) should all be 'OK'.
Perhaps more Python core developers would comment...
Nick Vatamaniuc
Dennis Lee Bieber wrote:
On 29 Jul 2006 07:26:57 -0700, "Nick Vatamaniuc" <va******@gmail.com>
declaimed the following in comp.lang.python:
Roman,
The way I see it, it could be either way. In other words if I can
write f(1,2,3) and f(1,2,3,) I should also be able to write
f(1,*[2,3],). It is a really small detail but there sould be some
consistency. Either no extra commas for all kinds of argument types or
Part of the problem may be that the * notation implies that the
associated argument is supposed to fill ALL other supplied positional
arguments -- so what is that empty argument after the , supposed to be
associated with? A positional argument /after/ all positional arguments?
--
Wulfraed Dennis Lee Bieber KD6MOG wl*****@ix.netcom.com wu******@bestiaria.com HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: we******@bestiaria.com) HTTP://www.bestiaria.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alberto Vera |
last post by:
Hello:
I have the next structure:
How Can I make it using Python?
How Can I update the value of 6?
|
by: Paul Davis |
last post by:
I'd like to overload 'comma' to define a concatenation operator for
integer-like classes. I've got some first ideas, but I'd appreciate a
sanity check. The concatenation operator needs to so...
|
by: JKop |
last post by:
void Blah(int k) { k; }
int main()
{
int a;
int b;
Blah( ++a, ++b );
}
|
by: Michael Scarlett |
last post by:
I was just curious as to why i could not write a function like the
following:
int bad_limits(int begin, end, low, high){
int not_good = 0;
if (begin > end){
printf("%d isn't smaller than...
|
by: Shawn Odekirk |
last post by:
Some code I have inherited contains a macro like the following:
#define setState(state, newstate) \
(state >= newstate) ? \
(fprintf(stderr, "Illegal...
|
by: G Patel |
last post by:
Hi,
I've read a book on C, and I understand how comma operators work, but
my book didn't say that the comma operators between function arguments
were not really comma operators (even though it...
|
by: siliconwafer |
last post by:
Hi,
In case of following expression:
c = a && --b;
if a is 0,b is not evaluated and c directly becomes 0.
Does this mean that && operator is given a higher precedence over
'--'operator?
as...
|
by: MattyWix |
last post by:
Hi,
How can I pass a semicolon or a comma as a macro argument.
I wish to build an expression that in some cases has a comma - eg
building a list of members for a structure, but in other...
|
by: mac |
last post by:
Hi,
I'm trying to write a fibonacci recursive function that will return
the fibonacci string separated by comma. The problem sounds like this:
-------------
Write a recursive function that...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |