Python中文
首页
教程
问答
标签
搜索
登录
注册
使用Python从另一个目录访问文件时出错
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>这是我的Python代码:</p> <pre class="lang-py prettyprint-override"><code>from plugin import Plugin import logging import yaml log = logging.getLogger('discord') def get_bot_prefix(): with open('HarTex/hartexConfig.yaml', 'r') as prefixReader: prefixValue = yaml.safe_load(prefixReader) prefixString = prefixValue['settings']['prefix'] return prefixString prefix = get_bot_prefix() </code></pre> <p>但是,我在访问文件时出错:</p> <pre><code>Traceback (most recent call last): File "C:/Users/85251/Documents/Discord Bots/Python/HarTex/bot.py", line 20, in <module> from plugins.help import Help File "C:\Users\85251\Documents\Discord Bots\Python\HarTex\plugins\help.py", line 30, in <module> prefix = get_bot_prefix() File "C:\Users\85251\Documents\Discord Bots\Python\HarTex\plugins\help.py", line 22, in get_bot_prefix with open('HarTex/hartexConfig.yaml', 'r') as prefixReader: FileNotFoundError: [Errno 2] No such file or directory: 'HarTex/hartexConfig.yaml' </code></pre> <p>我怎样才能修好它?还是我的目录完全错了</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>错误很明显。您应该使用绝对路径而不是相对路径</p> <p><strong>例如</strong>home/Prakash/Desktop/test12/test.yaml</p> <p>您的代码肯定能工作,一旦您像这样更改路径</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
当pandas中出现小数据时,DataFrame.resample()被调用时,内存不足
4 回答
当Pandas中存在许多条件时,如何过滤数据?
3 回答
当pandas中没有公共列名时,我们应该如何组合多个数据集而不在行或列中重复
2 回答
当pandas中的值为null时,不使用pandas的to_列表
2 回答
当Pandas中的值和条目匹配时,如何计算键的计数?
8 回答
当pandas列中有字符串时,如何从该列获取最长长度的string/integer/float
4 回答
当pandas列重命名创建列名重复时该怎么办
6 回答
当Pandas在带有颜色标签的多个子图中创建散点图时,无法设置xlabel
5 回答
当pandas导入openpyxl模块时,该模块没有属性''uuuversion''
6 回答
当pandas数据在python中聚合时,如何计算每组尾部的sum | mean |中值
6 回答
当Pandas数据头以列(如xls)拆分时,如何读取Pandas数据头
3 回答
当Pandas数据帧包含nan时,用“新信息”更新Pandas数据帧
10 回答
当pandas是imp时,Cx\u freeze TypeError只能使用numpy依赖项将list(而不是“NoneType”)连接到list
9 回答
当Pandas满足一定条件时,如何放弃整个群体
6 回答
当Pandas的时间增量指数不规则时,如何获得时间序列值的日差?
6 回答
当Pandas通过read\u csv方法读取大文件时。IOError:[Errno 13]权限被拒绝
10 回答
当panda列有空值时,如何将其转换为int?
8 回答
当param=''时使用Beautiful Soup访问属性的参数
5 回答
当paramiko抛出“无现有会话”异常时,标准输入流挂起
1 回答
当parentchild在同一端口上监听时会发生什么?
3 回答