File path with error to execute mp3

0

I was solving a proposed exercise in a course that was to execute an mp3 file passing the same path, I researched a little and I got to this code:

from playsound import playsound
playsound('C:\Downloads\c.mp3')

When I ran it gave error:

To solve it was proposed that I put it this way:

from playsound import playsound
playsound('C:\Downloads\c.mp3')

I did not understand why from the 2 \\ to the file path, could anyone explain?

    
asked by anonymous 01.08.2017 / 07:18

1 answer

3

The notorious "backslash" used in windows has a function in python, unix systems, regular expressions and some other programming languages, such as C and Perl, their function is to indicate that the next character must be treated In this context, it is also called an escape character that can form a scape sequence, see some of them (note the "Backbar"):

\a - BEL Bell
\b - BS (ascii) BackSpace
\f - FF Formfeed
\n - LF NewLine
\r - CR Carriage Return
\t - HT Horizontal Tabulation
\v - VT (ascii) Vertical Tabulation
\' - Apóstrofe (Single quotation mark)
\" - Aspas (Double quotation mark)
\ - Contrabarra
\ooo - Caracter ASCII em notação octal
\xhhh - Caracter ASCII em notação hexadecimal

As python also uses the backslash as the start of escape sequences, in the case of your question, it is doing a kind of "escape escape", ie, to consider the next character as a common character and not as the beginning of a scape sequence.

    
01.08.2017 / 07:45