0

so this is my code:

csvfile = open("T0\usuarios.csv", "r", encoding="utf-8")

for row in csvfile:

    print(row.split(","))

im working on a folder called "T0" where is my python file and also my csv file called "usuarios.csv", i have tried everything but i kept getting the error that says in the tittle or it says that cant find my csv file, im working with a relative path and i cant work with an absolute path but idk what im doing wrong.

Daniel F
  • 13,684
  • 11
  • 87
  • 116
kevin
  • 1
  • 2
    Backslashes are normally interpreted as an escape character inside a string literal; perhaps the most common use is `\n` to produce a newline character. If you want an *actual backslash* in the string, you either need to double it, or put an `r` in front of the opening quote mark to make it a raw string literal. – jasonharper Mar 20 '22 at 03:35
  • I already tried that :/ and i get this response from vscode " No such file or directory: " – kevin Mar 20 '22 at 03:42
  • Well, then your current working directory is apparently not where `T0` is located. – jasonharper Mar 20 '22 at 03:46
  • should try add r before path . ie csvfile = open(r"T0\usuarios.csv", "r", encoding="utf-8") source of answer : https://stackoverflow.com/a/37402939/9222942 – Mr Noob Jun 28 '22 at 20:56
  • 1
    Where are you executing your script from? From inside the T0-directory or from somewhere else? – Hyalunar Dec 31 '22 at 21:51
  • If `T0` is the current working directory, from which you are running python, then you should just be calling `open('usuarios.csv', 'r', encoding='utf-8')`. If you include the 'T0', then its trying to find that subdirectory first, which doesn't exist – nigh_anxiety Dec 31 '22 at 21:57

0 Answers0