python if and same instruction line not working

pascal z barpasc at yahoo.com
Sun Oct 4 05:35:17 EDT 2020


On Tuesday, September 29, 2020 at 5:28:22 PM UTC+2, MRAB wrote:
> 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".

Very good point, it should what caused the issue

By the way, it seems it's ok to check \n as end of line, it will work on windows linux and mac platforms even if windows use \r\n


More information about the Python-list mailing list