python if and same instruction line not working
MRAB
python at mrabarnett.plus.com
Tue Sep 29 11:27:43 EDT 2020
On 2020-09-29 15:42, pascal z via Python-list wrote:
> I need to change the script commented out to the one not commented out. Why?
>
> # for x in sorted (fr, key=str.lower):
> # tmpstr = x.rpartition(';')[2]
> # if x != csv_contents and tmpstr == "folder\n":
> # csv_contentsB += x
> # elif x != csv_contents and tmpstr == "files\n":
> # csv_contentsC += x
>
> for x in sorted (fr, key=str.lower):
> if x != csv_contents:
> tmpstr = x.rpartition(';')[2]
> if tmpstr == "folder\n":
> csv_contentsB += x
> elif tmpstr == "file\n":
> csv_contentsC += x
>
You haven't defined what you mean by "not working" for any test values
to try, but I notice that the commented code has "files\n" whereas the
uncommented code has "file\n".
More information about the Python-list
mailing list