Applications Google
Menu principal

Post a Comment On: Only Python

"(NOT) Bitten by PEP 3113"

4 Comments -

1 – 4 of 4
Blogger Unknown said...

Only tuple unpacking in function arguments has been deprecated; you can of course still pass two tuples as arguments to a function. For example,

def line((x1, y1), (x2, y2)):
# ...

can be rewritten:

def line(p1, p2):
x1, y1 = p1
x2, y2 = p2
# ...

the user API does not change.

11:55 PM

Blogger André Roberge said...

Alex:

I realize this - I gave that as the second alternative. However, it means that a user calling the line function would have to do

p1 = (100, 100)
p2 = (200, 200)
line(p1, p2)

which is not as "simple" as simply writing
line((100, 100), (200, 200))

12:11 AM

Blogger Unknown said...

I'm think you're mistaken:

>>> def line(p1, p2):
... x1, y1 = p1
... x2, y2 = p2
... print x1, y1, x2, y2
...
>>> line((100, 100), (200, 200))
100 100 200 200
>>>

12:39 AM

Anonymous Anonymous said...

In line with Alex, reading PEP3113 closely, under the "No Loss of Abilities If Removed" heading, states that you can still pass in tuples, they just can't be unpacked automatically.

12:40 AM

Spammers: none shall pass.
You can use some HTML tags, such as <b>, <i>, <a>

Comments on this blog are restricted to team members.

You will be asked to sign in after submitting your comment.
Please prove you're not a robot