1 import json 2 import os 3 queues=vars.get("queues") #獲取json提取器中提取的queues結果 4 queues1=eval(queues.replace('null', 'None', 99999))#將返回的queues中的null替換成None(python不認識null,在python中使用None) 5 #eval可以把 list, tuple, dict 轉換成str,返回來也成立;即互轉。 6 #str.replace(old,new,max):把字符串中的old(舊字符串替換成new(新字符串),如果指定第三個參數max,則替換不超過 max 次 7 8 #log.info(queues1)#打印日志 9 workspace=vars.get("workspace");#獲取文件目錄地址(workspace是存放地址,在全局變量中定義好) 10 txtPath=os.path.join(workspace,'waitingPatient3.txt')#拼接文件地址 11 f = open(txtPath, 'a+')#追加方式寫入文件(a+沒有此文件會先創建) 12 for ever in queues1:#循環遍歷寫入文件 13 # log.info(ever) 14 f.writelines([ever['doctorName'],',', ever['doctorId'],',', ever['patientId'],',',ever['patientName'],',',ever['visitNumber'],',', ever['appointmentId'],',',ever['triageId'],',',ever['tenantDeptId']+'\n']) 15 f.close()
注釋:
1.replace()方法:
Python replace() 方法把字符串中的 old(舊字符串) 替換成 new(新字符串),如果指定第三個參數max,則替換不超過 max 次。
2.eval()方法:
eval 可以把 list, tuple, dict 轉換成str,返回來也成立;即互轉。
詳見:https://www.cnblogs.com/jianguo221/p/8975899.html