Red text after "/". Make unreadable [duplicate] - python

This question already has answers here:
How should I write a Windows path in a Python string literal?
(5 answers)
Closed 15 days ago.
enter image description here
i use Python and Visual Studio Code IDE
Is there a way to fix this?

Backslashes in strings are ”escape characters” used to signify special characters such as newline (\n), tab (\t), and so on.
To put an actual backslash in a string, use a double backslash: this\\that, or use an r-string: r”this\that”.

Related

Adding a absolute path that has a \f in it [duplicate]

This question already has answers here:
How can I put an actual backslash in a string literal (not use it for an escape sequence)?
(4 answers)
Closed 3 months ago.
While adding an absolute path to my script because it has a \f in it the code won't run properly.
C:\Users\showoi\Desktop\website\repository\fileAdder\softwarelisting.xlsx
The file is in the same directory as the script but using a relative path won't work. No misspellings or anything.
Use python r string
path=r'C:\Users\showoi\Desktop\website\repository\fileAdder\softwarelisting.xlsx'
Use one of the following ways:
r"C:\Users\showoi\Desktop\website\repository\fileAdder\softwarelisting.xlsx"
"C:\\Users\\showoi\\Desktop\\website\\repository\\fileAdder\\softwarelisting.xlsx"
"C:/Users/showoi/Desktop/website/repository/fileAdder/softwarelisting.xlsx

How to Type in Escape Characters in Python 3 Input() Function? [duplicate]

This question already has answers here:
Python 3: receive user input including newline characters
(2 answers)
Process escape sequences in a string in Python
(8 answers)
Closed 9 months ago.
I am looking to type from the Python Console in Pycharm to respond to a call from input(). I would like to somehow get a newline into this string, but when I try to literally type "\n", input() automatically escapes the escape backslash into something like result = "\n" so that what I typed exactly will be printed out if I use print(result).
Demonstration of problem

I'm trying to use /b, but it doesn't actually backspace, but it inserts the character [duplicate]

This question already has answers here:
Backspace does not seem to work in python
(6 answers)
What is the use of '\b' (backspace)
(5 answers)
Closed 2 years ago.
So I've been trying to use the backspace (\b) character in my code, but for some reason, my python does not actually delete a character, it literally inserts a backspace character. Is there any way to go around this issue, or do I have to use another way?
My Code:
print('Hello World!\b')
The output:
Hello World!
If you are doing this in IDLE , know that \b is not supported.

\r or \n added in arguments list from Python [duplicate]

This question already has answers here:
How can I remove a trailing newline?
(27 answers)
Closed 6 years ago.
i have some scripts that take as input one or multiple paths as on argument.
The script is run like that: myScript.py D:\Folder1,E:\OtherData\Files
In the script, i split the path arguments in the comma and i read the paths.
The problem is that Python adds a \r in the end of each path for no reason.
So the script tries to read D:\Folder1\r and E:\OtherData\Files\r.
Why is this and how can i solve it?
There are many ways, here is one for example.
Replacing the relevant problematic string with an empty string:
paths= [x.rstrip() for x in paths_list]
The method rstrip() returns a copy of the string in which all chars have been stripped from the end of the string (default whitespace characters).

read escaped character \t as '\t' instead of '\\t' Python ConfigParser [duplicate]

This question already has answers here:
Process escape sequences in a string in Python
(8 answers)
Closed 7 months ago.
I have a config.ini file containing delimiter = \t which i now want to read using the python3 ConfigParser.
However, the resulting string is '\\t' instead of '\t' which breaks my program.
Is there a more elegant option to solve this problem instead of just manually stripping the extra '\' from every variable containing an escaped character?
I cannot find an option for ConfigParser().read() to not escape the backslash it finds in the file.
Python3 has a 'unicode_escape' codec.
r"a\tb".decode('unicode_escape')
'a\tb'
Sources:
https://bytes.com/topic/python/answers/37952-escape-chars-string
how do I .decode('string-escape') in Python3?

Categories