#config.ini
[server] interfaceURI = http://localhost:8080/dub/ downloadURI = http://127.0.0.1:7056/data/ saveDir = D:/temp/singlewindow/data/ agentCode = 3122263935
#config.py
import configparser def getConfigValue(section, key): config = configparser.ConfigParser() config.read("config.ini") return config.get(section, key) print(getConfigValue("server","interfaceURI "))
Second, read the file
def readfile(filename): f = open(filename,'r',encoding= 'utf8') # read mode s=f.read() # Read the entire file at once, not suitable for large files f.close() return s
3. Multithreading
from time import sleep def downloadmessage(): print("The download message thread starts to start...") while (True): #do download def uploadreceipt(): print("Upload receipt thread starts...") while (True): #do upload if __name__ == '__main__': threads = [] t1 = threading.Thread(target=downloadmessage) threads.append(t1) t2 = threading.Thread(target=uploadreceipt) threads.append(t2) for t in threads: t.setDaemon(True) t.start() t.join() print("The main thread has finished running...")
Fourth, exception handling
try: files = httprequest.getFileByRequests() arr=json.loads(files) for i in range(0, len(arr)): download.downloadFile(arr[i].get('fileName')) except: print("Unexpected error:", sys.exc_info()[0]) finally: sleep(1)
Five, package and
install pyinstaller, see the python study notes for the installation method [1]
#Type into launcher.exe pyinstaller -F -i c:\zjport.ico launcher.py