Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #49810
| From | alex23 <wuwei23@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Why this code works in python3, but not python 2: |
| Date | 2013-07-04 14:47 +1000 |
| Organization | A noiseless patient Spider |
| Message-ID | <kr2udr$tvv$1@dont-email.me> (permalink) |
| References | <e0ffc562-4016-4b5d-88c3-5a115da16906@googlegroups.com> <mailman.4202.1372911189.3114.python-list@python.org> |
On 4/07/2013 2:12 PM, Joshua Landau wrote:
> On 4 July 2013 04:52, Maciej Dziardziel <fiedzia@gmail.com> wrote:
>> def foo(*args, bar=1, **kwargs):
>> pass
> Try "foo(1)" and it will fail -- "bar" needs to be given as a keyword.
No it won't, because it is supplied with a default. You may be
confusing it with the requirement that `bar` must be given as a keyword
in order for it to override the default, compared to the way this would
need to be written in Py2:
def foo(bar=1, *args, **kwargs):
...
...in which case `bar` could be assigned to by the first positional
argument.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why this code works in python3, but not python 2: Maciej Dziardziel <fiedzia@gmail.com> - 2013-07-03 20:52 -0700
Re: Why this code works in python3, but not python 2: alex23 <wuwei23@gmail.com> - 2013-07-04 14:05 +1000
Re: Why this code works in python3, but not python 2: Maciej Dziardziel <fiedzia@gmail.com> - 2013-07-03 21:31 -0700
Re: Why this code works in python3, but not python 2: Chris Angelico <rosuav@gmail.com> - 2013-07-04 14:10 +1000
Re: Why this code works in python3, but not python 2: Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-04 05:12 +0100
Re: Why this code works in python3, but not python 2: alex23 <wuwei23@gmail.com> - 2013-07-04 14:47 +1000
Re: Why this code works in python3, but not python 2: Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-04 06:10 +0100
csiph-web