Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.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 在多个子目录上运行代码_Python - Fatal编程技术网

Python 在多个子目录上运行代码

Python 在多个子目录上运行代码,python,Python,我想在多个文件上运行一些代码,每个文件都包含在自己的子目录中。我想编写一些额外的代码,要求用户输入子目录名,打开子目录,并在其中包含的文件上运行代码(每个子目录中只包含一个文件)。有人能帮忙吗?通过这个循环,您可以通过根文件夹的子文件夹操作所有文件 import os for root, dirs, files in os.walk('Your path here'): for file in files: //your code here// 您是否阅读了os内置模

我想在多个文件上运行一些代码,每个文件都包含在自己的子目录中。我想编写一些额外的代码,要求用户输入子目录名,打开子目录,并在其中包含的文件上运行代码(每个子目录中只包含一个文件)。有人能帮忙吗?

通过这个循环,您可以通过根文件夹的子文件夹操作所有文件

import os

for root, dirs, files in os.walk('Your path here'):
    for file in files:
        //your code here//

您是否阅读了
os
内置模块的文档?具体来说,您会发现
os.listdir
以及
os.path.join