Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/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 Can';t在google cloud笔记本实例中迭代文件夹中的文件_Python_Google Cloud Platform_Jupyter Lab_Google Cloud Ai - Fatal编程技术网

Python Can';t在google cloud笔记本实例中迭代文件夹中的文件

Python Can';t在google cloud笔记本实例中迭代文件夹中的文件,python,google-cloud-platform,jupyter-lab,google-cloud-ai,Python,Google Cloud Platform,Jupyter Lab,Google Cloud Ai,我正在谷歌云控制台的AI平台中使用笔记本实例。我上传了一个文件夹,里面包含大约30个csv文件 我运行以下代码对文件进行迭代 for subdir, dirs, files in os.walk('~/uploadedfiles/'): for file in files: filepath = os.path.join(subdir, file) print(filepath) 然而,出于某种原因,我似乎可以遍历这些文件。单元格的结尾没有错误。如何修复

我正在谷歌云控制台的AI平台中使用笔记本实例。我上传了一个文件夹,里面包含大约30个csv文件

我运行以下代码对文件进行迭代

for subdir, dirs, files in os.walk('~/uploadedfiles/'):
    for file in files:
        filepath = os.path.join(subdir, file)
        print(filepath)

然而,出于某种原因,我似乎可以遍历这些文件。单元格的结尾没有错误。如何修复此问题?

尝试将~替换为完整路径。Python可能不会在该tilde上进行bash扩展:

$ cat bork.py 
#!/usr/bin/env python3
import os

for subdir, dirs, files in os.walk('/Users/inger.klekacz/parent/'):
    for file in files:
        filepath = os.path.join(subdir, file)
        print(filepath)

这适用于此目录结构:

- parent/
  - foo.txt
  - child1/
    - bar.txt
  - child2/
    - baz.txt
像这样:

$ ./bork.py 
/Users/inger.klekacz/parent/foo.txt
/Users/inger.klekacz/parent/child2/baz.txt
/Users/inger.klekacz/parent/child1/bar.txt
但我用瓷砖的时候没用