繁体   English   中英

如何停止 python 以完成一个操作的执行然后启动其他进程

[英]How to STOP python to complete execution on one operation and then start other process

def fun1():
    #something(opens a command window in a folder and run something)
    os.system("start cmd /c omake clean ")
def fun2():
    #something(opens a command window again in the same folder and run something else)
    os.system("start cmd /c omake ")

for dir in list_of_dir:
    os.chdir(dir)
    fun1()
    fun2()

#上面的结构只是一个例子,如果你在for循环中看到fun1()和fun2() #calls同时发生#但是有人怎么能先完全执行fun1()包括关闭命令window #然后才移动在 python 中调用 fun2()。

#请在这方面指导我..

#谢谢。

请避免以这种方式运行脚本。 也不要命名变量,如 dir。 获得一个做一些 linting 的编辑器有很大帮助

只是一个例子。 还是知道你想达到什么目标会更好?

import os
from os import listdir
from os.path import isfile, join

def fun1():
    os.system("dir")
    print('fun1: done!')
    
    
def fun2():
    os.system("dir")
    print('fun1: done!')


path_folder = "c:/Windows"
file_names = [f for f in listdir(path_folder) if isfile(join(path_folder, f))]


for filen_name in file_names:
    os.chdir(path_folder)
    fun1()
    fun2()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM