公司最近接了乙個新專案,支氣管導航。為了驗證軟體的功能,就需要跑很多例項,這時候就會用到指令碼跑資料,就不需要一遍遍手動執行軟體。先上**:
import os
import sys
import subprocess
extractionexe = "airwaycenterlineextractionengine2.exe" #這是我們演算法工程師寫的乙個提取中心線的exe
def runalgorithm(src, dest): #函式定義
for root,dirs,files in os.walk(src):
for dir in dirs:
basedir = os.path.join(src, dir)
destdir = os.path.join(dest, dir)
if not os.path.exists(destdir):
os.mkdir(destdir)
srcfile = os.path.join(basedir, "data.mhd")
if not os.path.exists(destdir):
continue
destfile = os.path.join(destdir, "extract.mhd")
if not os.path.exists(destfile):
continue #這兩句是優化,如果該資料資料夾下已經生成了目標檔案extract.mhd,則跳出繼續下乙個資料
print("start extract centerline for " + dir)
arguments = [extractionexe, srcfile, destfile]
proextraction = subprocess.popen(arguments, stdout=subprocess.pipe, cwd=".")
try:
stdoutput,erroutput = proextraction.communicate(timeout=60 * 10)
print(erroutput)
except subprocess.timeoutexpired:
print("extraction expired.")
proextraction.kill()
break
srcdir = r"c:\data"
destdir = r"c:\data"
runalgorithm(srcdir, destdir) #函式宣告
由於之前沒學過python,現在也是邊學邊用,這是根據上司寫的指令碼照葫蘆畫瓢得來的結果,沒想到還是通過了。感覺python對**要求沒有c++嚴格。
先說一下大概功能:執行演算法工程師寫的 airwaycenterlineextractionengine2.exe,根據data.mhd檔案提取出中心線生成extract.mhd檔案。所有資料都在同乙個資料夾下,乙個資料是乙個資料夾,從前往後跑完資料夾裡所有的資料。
basedir :基礎檔案路徑
srcdir : 原始檔案路徑
destdir : 目標檔案路徑
dir :每個資料的檔名
srcfile : 原始檔案
destfile :目標檔案
用Python寫課程提醒程式(一)
課程資訊儲存 時間 周,天 引入 程式遍歷每門課程的時間屬性 主程式獲取對應的時間屬性與引入時間屬性相符的課程屬性 主程式將獲取到的所有課程打包成陣列 呼叫郵件程式傳送課程到手機郵箱 一.資料產生 1 課程資訊儲存 考慮到可以推廣的話,可以寫乙個資料儲存介面,類似於課程格仔那樣子的,然後通過使用者互...
用Python寫指令碼,完全備份和增量備份
需求 在 root backup下面有兩個資料夾dst和src。要求在周一的時候進行完全備份,其餘日子進行增量備份。從src備份到dst。思路及關鍵點 建立乙個檔案,以字典方式記錄src的檔名以及檔案對應的md5的值 完全備份的時候將檔名和md5值寫在乙個檔案裡面。cpickle的知識點。增量備份的...
用指令碼寫帶選項的使用者指令碼
要求如下 只支援三個選項 del add help輸入其他選項報錯。使用 add 需要驗證使用者名稱是否存在,存在則反饋存在。且不新增。不存在則建立該使用者,切 新增與該使用者名稱相同的密碼。並且反饋。使用 del 需要驗證使用者名稱是否存在,存在則刪除使用者及其家目錄。不存在則反饋該使用者不存 在...