[Tutor] Long Lines techniques
Steven D'Aprano
steve at pearwood.info
Fri Dec 14 00:22:15 EST 2018
On Thu, Dec 13, 2018 at 11:07:59PM -0500, Avi Gross wrote:
[...]
> There are cases where it may make sense to have a long like connected by AND
> or OR given how python does short-circuiting while returning the last thing
> or two it touched instead of an actual True/False. For example, you may want
> to take the first available queue that is not empty with something like
> this:
>
> Using = A or B or C or ... or Z
> Handling = Using.pop()
>
> Sure, that could be rewritten into multiple lines.
using = (A or B
or C or D
or E or F)
[...]
> I recently wrote some code and ran into error messages on lines I was trying
> to keep short:
>
> A = 'text"
> A += "more text"
> A += object
> A+= ...
Without knowing the error message, its impossible to say what the
problem is. My guess is that the object on line three wasn't a string.
In which case, the obvious fix is:
A += str(object)
--
Steve
More information about the Tutor
mailing list