擅长:python、mysql、java
<p>最后,问题不在于<code>os.chdir()</code>。这个问题与@user2357112提到的<code>os.system()</code>函数有关</p>
<p>由于<code>path</code>中的空格,<code>os.system()</code>命令给了我一些问题。因此,由于文件都位于同一个文件夹中,我刚刚删除了对<code>path</code>的引用,结果如下:</p>
<pre><code>import os
path = os.getcwd()
os.chdir(path)
directory = 'C:/Users/Desktop/scrap/'
files = ['scrape', 'tag', 'save', 'select']
if __name__ == '__main__':
if not os.path.isdir(directory):
os.mkdir(directory)
[os.system('python ' + f'{file}.py ' + directory) for file in files]
</code></pre>