The three ways to write a path + the meaning of the symbols before the path
1、
('E:/test/')
2、
('E:\\test\\')
3、
(r'E:\test\')
In python strings \ is an escape character, if you want \ to keep its original meaning, you can add r in front of the path to avoid escaping.
Note: The full name of r is raw string, i.e. raw string constant, which allows the character to keep its original meaning.
Additional additions:
url to read local file format: url = 'file:///E:/Filename/'
Meaning of the symbols before the load path (. /, ... /, /, ~/)
/ |
Indicates the root directory |
./ |
Indicates the current directory |
../ |
Indicates the upper level directory of the current directory |
~/ |
Indicates the Web application root directory |
The import here below is taken from:\site-packages\torch\nn\modules\。
After from it uses three dots "..." , indicating that from the directory two levels up from the current path where this code file is located (in this case, nn's sibling directory), find, and then import the RemovableHandle inside.
from ... import RemovableHandle
Python Chinese path representation
1. Be careful with Chinese paths! Be careful with Chinese paths! Be careful with Chinese paths!!!
result = pd.read_csv(u'F:/graduate coursework/JData_dataset/JData_User/JData_User.csv')
Due to the path of Chinese, remember to write #coding: utf-8 at the beginning of the code. and remember to add u where there is Chinese.
2. Don't use backslashes in windows paths in Python, this will report an error.
D:\feiq\feiq\Recv Files\Recv Files\LOS Dataset
The above is a direct copy of the path from windows, as you can see, the path is backslashed: \.
Since backslash \ in python also means escape. So writing paths directly like this can cause problems.
Solutions.Using any of the following forms of writing is fine:
- Use slash "/": "c:/"... no ambiguity without backslashes!
- Escape backslash symbols: "c:\\"... Since backslash is an escape character, two "\\" means one backslash symbol.
- Using Python's raw string: r "c:\" ... The letter r in front of a string under python indicates that it is followed by a raw string raw string, but raw strings are primarily designed for regular expressions rather than windows paths, so use this practice sparingly, it can cause This practice should not be used as much as possible, as it may cause problems.
summarize
The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.