Why does “/n” adds to my input - Tkinter, Python

Question:
I didn’t understand why does “/n” is every time adds into the input.
This is unacceptable for my system with file scanning, as I enter a file name without this ending, but it is added and makes it impossible to select that particular file, as there are no files with that ending.

Repl link:



IMG_0352
IMG_0353

For the photo example, I pressed the scan button without entering anything, but the ending was automatically added. I checked, file = what I entered and when printing This variable ending is not present, it is strictly added when trying to scan the file. If, on the other hand, you enter the file path in the field and then scan it, nothing happens, as the above strange ending is added to the file.

Try calling .strip() on the input, that should remove the trailing newline.
Example:

whee = input("Type something: ")
whee.strip()
3 Likes

Try casting it to an str first and then call .strip() or you could try replacing it .replace('\\n', '')

2 Likes

Replace wouldn’t work because it isn’t “/n” in the variable.

Then where are you seeing /n

It is only in the error.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.