Error file path to run mp3

Asked

Viewed 195 times

0

I was solving a proposed exercise in a course that consisted of running an mp3 file passing the path of it, I searched a little and I arrived at this code:

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

When I performed, I made a mistake:

inserir a descrição da imagem aqui

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

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

I don’t understand why at 2 o'clock on the way to the archive, someone could explain?

1 answer

3


The so-called "backslash" used in windows has a function in python, Unix systems, regular expressions and some other programming languages such as C and Perl, its function is to indicate that the following character should be treated in a special way, in this context is also called escape caracater that can form a scape sequence, see some of them (note the "Contrabarra"):

\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

Since python also uses the backslash as the beginning of escape sequences, in the case of your question, it is making a kind of "escape from escape", that is, indicating to consider the next character as a common character and not as the beginning of a scape sequence.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.