Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x pycharm并打开文件_Python 3.x_File_Pycharm_With Statement - Fatal编程技术网

Python 3.x pycharm并打开文件

Python 3.x pycharm并打开文件,python-3.x,file,pycharm,with-statement,Python 3.x,File,Pycharm,With Statement,我有一个从目录中打开文件的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_in

我有一个从目录中打开文件的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:
我的建议如下:

Unexpected type(s): 
(Path) 
Possible types: 
(Union[str, bytes, int]) 
(Union[str, bytes, int, PathLike])

我如何解决这个问题,为什么pycharm建议我这样做,即使代码仍然有效?

请投票(在问题标题附近竖起大拇指)

我认为截图会更好。添加了截图