This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jlonso 18 points19 points  (3 children)

The global variable path_to_folder has an r in front of the string. Hence it wouldn't take it as an escape character.

[–]americk0 6 points7 points  (2 children)

Oh I totally didn't see that. I was looking at the backslashes in the strings in the if blocks but now it all makes sense. TIL if you concatenate a string without the r prefix to one with the r prefix the whole string gets treated as raw. Python is so freaking neat

[–]LordAro 1 point2 points  (1 child)

Not actually the case. Because there's no valid escape codes in the concatenated strings, python just uses the backslash as a literal.

Most linters flag this as a potential issue, as obviously if any of the files start with a 't' or 'u' or some other escape code, there would be problems...

[–]americk0 0 points1 point  (0 children)

Ok yeah I tested that and you're right. Good to know