learning python ...

Grant Edwards grant.b.edwards at gmail.com
Tue May 25 12:14:46 EDT 2021


On 2021-05-25, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> On 25/05/21 5:56 pm, Avi Gross wrote:
>> Var = read in something from a file and make some structure like a data.frame
>> Var = remove some columns from the above thing pointed to by Var
>> Var = make some new calculated columns ditto
>> Var = remove some rows ...
>> Var = set some kind of grouping on the above or sort it and so on.
>
> As long as all the values are of the same type, this isn't too bad,
> although it might interfere with your ability to give the intermediate
> results names that help the reader understand what they refer to.

I do vaguely recall 20+ years ago when I first started writing Python
I recoiled at it, but now I don't find it to be a problem if all of
the assignments are close together as above (so that it's not possible
to see one and miss the others) and there's only one execution path
through that chunk of code.

I try to avoid it if they're spread out over hundreds of lines of code
or if there are paths that result in different types at the end.

> A variable that refers to things of different *types* at different
> times is considerably more confusing, both for a human reader and
> for any type checking software you might want to use.

Ah, I've never tried any type checking software, so that may explain
my lax attitude.

--
Grant



More information about the Python-list mailing list