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>如果您是从HarTex的父目录调用脚本,那么脚本应该可以工作,也许您是从其他工作目录运行它</p> <p>您还可以尝试使用完整路径打开文件,因为这可能很容易检查</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
当pandas中出现小数据时,DataFrame.resample()被调用时,内存不足
5 回答
当Pandas中存在许多条件时,如何过滤数据?
10 回答
当pandas中没有公共列名时,我们应该如何组合多个数据集而不在行或列中重复
3 回答
当pandas中的值为null时,不使用pandas的to_列表
2 回答
当Pandas中的值和条目匹配时,如何计算键的计数?
10 回答
当pandas列中有字符串时,如何从该列获取最长长度的string/integer/float
7 回答
当pandas列重命名创建列名重复时该怎么办
1 回答
当Pandas在带有颜色标签的多个子图中创建散点图时,无法设置xlabel
1 回答
当pandas导入openpyxl模块时,该模块没有属性''uuuversion''
3 回答
当pandas数据在python中聚合时,如何计算每组尾部的sum | mean |中值
5 回答
当Pandas数据头以列(如xls)拆分时,如何读取Pandas数据头
6 回答
当Pandas数据帧包含nan时,用“新信息”更新Pandas数据帧
5 回答
当pandas是imp时,Cx\u freeze TypeError只能使用numpy依赖项将list(而不是“NoneType”)连接到list
6 回答
当Pandas满足一定条件时,如何放弃整个群体
6 回答
当Pandas的时间增量指数不规则时,如何获得时间序列值的日差?
2 回答
当Pandas通过read\u csv方法读取大文件时。IOError:[Errno 13]权限被拒绝
2 回答
当panda列有空值时,如何将其转换为int?
5 回答
当param=''时使用Beautiful Soup访问属性的参数
3 回答
当paramiko抛出“无现有会话”异常时,标准输入流挂起
10 回答
当parentchild在同一端口上监听时会发生什么?
4 回答