簡單的製作一個 PYTHON 用的程式樣版,未來再開發 PYTHON 的程式,可以先拿這個樣版來用,只要在 main() 中加入要執行的事情,其他的 sub function ,再增加 def fun…(): 來使用
import os def fun1(paraml, secondParam): res = paraml +secondParam if res < 50: print('a') elif (res >50) and ((paraml==42) or (secondParam==24)): print('b') else : print('c') return res def main(): try: rtn=os.popen('dir') rtnStr=rtn.read() rtn.close() print(rtnStr) print(STR_Contains(rtnStr,'OK')) except IOError: print('Io Error') except: print('except error') finally: print('OK') def STR_Contains(SourceStr, ContainsStr): rtnValue = False Result=SourceStr.find(ContainsStr) if(Result>0): rtnValue=True return rtnValue if __name__ =='__main__': main()