int(a), b = divmod(x, y)

Bruce Sass bsass at freenet.edmonton.ab.ca
Thu Jul 26 07:25:54 CEST 2001


Ya, that's pretty much what I figured; well, that or maybe the
look-ahead required would involve more than a naive view suggests.

It didn't look too weird when I first wrote it, but a second look has
me thinking otherwise (Paul and Greg's posts kinda clinch it :).

I suppose if I ever get lazy enough to actually want such a thing...
it would be easy to do in a preprocessing step.


Thanks All.


- Bruce

-- 
On Wed, 25 Jul 2001, Ken Seehof wrote:
> No, it's just that the syntax makes no sense in python.
>
> It would also, of course, be invalid to say:
> int(a) = 5.2    # hoping for a=5
>
> This is not the same as a = int(5.2) and it would seem really wierd to
> me if it were.  Then again, from a C++ point of view, any syntax that
> is currently illegal is a natural candidate for a new syntax feature :-).
> But python is not C++, so I'm afraid you'll have to settle for something
> less terse and more clear.
>
> a,b = divmod(x,y)
> a = int(a)
>
> ----- Original Message -----
> From: "Bruce Sass" <bsass at freenet.edmonton.ab.ca>
> > How nasty would it be to allow one to do...
> >
> > >>> int(a), b = divmod(5.01, 2)
> > >>> print a, b
> > 2 1.01
> >
> > ...instead of the current...
> >
> > >>> int(a), b = divmod(5.01, 2)
> > SyntaxError: can't assign to function call
> >
> > On the surface, it looks as simple as postponing the function call
> > until after the assignment.  Would it be a one-time hit when the
> > pseudo-ops are generated, a runtime performance issue that would
> > affect all function calls, just too hairy to implement, or something
> > else?






More information about the Python-list mailing list