簡體   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