Python os.remove-目录中没有这样的文件 [英] Python os.remove - No such file in directory

查看:674
本文介绍了Python os.remove-目录中没有这样的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码来删除本地文件夹之一中的文件.我已经从其他用户帖子中获取了代码.

I have below code to remove a file in one of my local folders. I have taken the code from other user posts.

但是,它似乎对我不起作用.以下是我的代码

However, it does not seem to be working for me. Below is my code

python

import os

def deletefile():
    filePath = "‎⁨‎⁨/Users/Jose/Documents"
    os.remove(os.path.join(filePath, "tweets.db"))
    print("Ok while deleting file ", filePath)

deletefile()

以下是我遇到的错误.我究竟做错了什么?为什么Python在我的路径前放置"\ u200e \ u2068 \ u200e \ u2068/"?

And below is the error that I am getting. What am I doing wrong? Why Python is placing "\u200e\u2068\u200e\u2068/" in front of my path?

Traceback (most recent call last):
  File "tests.py", line 17, in <module>
    deletefile()
  File "tests.py", line 11, in deletefile
    os.remove(os.path.join(filePath, "tweets.db"))
FileNotFoundError: [Errno 2] No such file or directory: '\u200e\u2068\u200e\u2068/Users/Jose/Documents/tweets.db'

推荐答案

手动重新输入变量filePath = /Users/Jose/Documents

字符串中有一些不可见的'LEFT-TO-RIGHT MARK' (u200e)'FIRST STRONG ISOLATE' (u2068)字符

There are some invisible 'LEFT-TO-RIGHT MARK' (u200e) and 'FIRST STRONG ISOLATE' (u2068) characters in the string

这篇关于Python os.remove-目录中没有这样的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆