0

I am using Spyder when I import the environmental variables using:

import sys
print(sys.path)

I get the following:

['C:\\Users\\james', 'C:\\Python\\Anaconda3\\python37.zip', 'C:\\Python\\Anaconda3\\DLLs', 'C:\\Python\\Anaconda3\\lib', 'C:\\Python\\Anaconda3', '', 'C:\\Python\\Anaconda3\\lib\\site-packages', 'C:\\Python\\Anaconda3\\lib\\site-packages\\win32', 'C:\\Python\\Anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\Python\\Anaconda3\\lib\\site-packages\\Pythonwin', 'C:\\Python\\Anaconda3\\lib\\site-packages\\IPython\\extensions', 'C:\\Users\\james\\.ipython']

I am wondering why I get double backslashes, while the tutorial I am watching displays the paths with a single forward slash. eg

['C:/Users/james', ...
James
  • 123
  • 9
  • possible duplicate [this](https://stackoverflow.com/questions/11924706/how-to-get-rid-of-double-backslash-in-python-windows-file-path-string). – Lau Real Jul 23 '20 at 10:15
  • when you use `print(list)` then it `repr()` to display elements on list to show all important information - like \\ - useful for debuging. If you print every item separatelly then it will print single \ - `for item in sys.path: print(item)` – furas Jul 23 '20 at 10:34

1 Answers1

2

The difference is that your tutorial is on not-windows system, and directories are like this/is/path. On Windows, the directories are like this\is\path. But in Python and in most programming languages, \(backslash) is used for escapes, so to writethis\is\path you need to write 2 slashes.

Dave Benson
  • 161
  • 6