python-3.x - pycharm和打开文件建议int
问题描述
我有一个从目录打开文件的def,在其中我有文件并希望迭代每个文件以制作某些东西
def read_decks_from_disk():
deck_list = []
basepath = Path("Decks\\")
for filename in basepath.iterdir():
if filename.is_file():
with open(filename) as file:
deck_info = file.read().splitlines()
d = {
"nome": deck_info[0],
"formato": deck_info[1],
"prezzo": deck_info[2]
}
deck_list.append(d)
return deck_list
当我使用:
with open(filename) as file:
pycharm 建议我这样做:
Unexpected type(s):
(Path)
Possible types:
(Union[str, bytes, int])
(Union[str, bytes, int, PathLike])
我该如何解决这个问题以及为什么 pycharm 建议我这样做,即使代码仍然有效?
解决方案
请投票给https://youtrack.jetbrains.com/issue/PY-30747(在问题标题附近竖起大拇指)
推荐阅读
- python - 如果写作的行为方式不同,为什么经典和内联?
- kotlin - 是否可以为 Kotlin 原始数组创建通用函数
- reactjs - 无法从 ReactPrime 复制 DataTable 中的纯文本
- javascript - 自动文件上传
- acumatica - 如何使用 Coalesce 和 PXProjection 的示例?
- flutter - 如何等到 Finder 在 Flutter 集成测试中显示下一个代码执行?
- javascript - 十进制的正则表达式模式匹配
- amazon-web-services - 如何删除 AWS Rekognition 自定义标签数据集
- c - 为什么我在使用睡眠功能时需要在 c 中使用“\n”?
- c - 从文件中读取一个双数 - c