【问题标题】:pycharm and open file suggested intpycharm和打开文件建议int
【发布时间】:2020-03-11 18:35:40
【问题描述】:

我有一个从目录打开文件的 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 建议我这样做,即使代码仍然有效?

【问题讨论】:

  • 我觉得截图会更好。
  • 添加截图

标签: python-3.x file pycharm with-statement


【解决方案1】:

请投票给https://youtrack.jetbrains.com/issue/PY-30747(在问题标题附近竖起大拇指)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-16
    • 2017-01-11
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    相关资源
    最近更新 更多