This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2017年08月02日 07:25 by 007hengxyx, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg299645 - (view) | Author: Re-ax (007hengxyx) | Date: 2017年08月02日 07:25 | |
I need to remove a file in python at Windows2012R2, but, os.remove()auto add \ in each seq. code: #coding=utf-8 import os dir_path='d:\c\d\e\t\c\t.xf' os.remove(dir_path) result: Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> Traceback (most recent call last): File "D:\test\script\test.py", line 4, in <module> os.remove(dir_path) WindowsError: [Error 3] The system cannot find the path specified: 'd:\\c\\d\\e\t\\c\t.xf' >>> |
|||
| msg299646 - (view) | Author: Paul Moore (paul.moore) * (Python committer) | Date: 2017年08月02日 07:42 | |
There are two problems with your code and bug report: 1. By using a single quoted string, some of the backslashes in the path are being interpreted as starting a special character (specifically \t is interpreted as a tab character). You should either double the backslashes to prevent this interpretation (dir_path='d:\\c\\d\\e\\t\\c\\t.xf'), use forward slashes (dir_path='d:/c/d/e/t/c/t.xf') or use a raw string (dir_path=r'd:\c\d\e\t\c\t.xf'). 2. You're reporting that Python "auto adds \". It doesn't, it's just that the repr of the string shows a single quoted string with backslashes doubled - that's the standard repr for strings. So, Python is behaving as expected, and there's no bug here. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:49 | admin | set | github: 75284 |
| 2017年08月02日 07:42:15 | paul.moore | set | status: open -> closed resolution: not a bug messages: + msg299646 stage: resolved |
| 2017年08月02日 07:25:45 | 007hengxyx | create | |