devwiki:python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
devwiki:python [2024/01/06 19:45] – [Python and interaction with other API] yingdevwiki:python [2024/03/25 06:36] (current) – [Python and interaction with other API] ying
Line 1: Line 1:
 +
 +
 +====== Modern Python Practice ======
 +
 +  * nowaday, now one use python 2.x anymore, use python 3 standard, use this
 +    * use pathlib instead of os.path
 +    * use f"{keyword}" instead of "{0}".format(keyword), unless it is easier
  
  
Line 937: Line 944:
 except OSError: except OSError:
     pass     pass
 +    
 +# method 3: all in one check and create if needed, like method 2 but not need try and except since it will be ok for exist
 +os.makedirs(os.path.dirname(output_path), exist_ok=True)
 </code> </code>
   * write python data<code python>   * write python data<code python>
Line 2405: Line 2415:
 # chat (first_name, id, type); date:int; message_id; text # chat (first_name, id, type); date:int; message_id; text
 </code> </code>
 +
 +====== Python and Networking related ======
 +
 +  * above is python interact with a REST API server, you can also use python to build your own REST API server to handle requests from other application, even other application over the network and internet.
 +  * implement REST API into python, you may need to use some python module like Flash, FastAPI, then you start another thread from your python application to run your REST API server.
 +  * while using Sockets method may be simpler if you just want to send some simple message between applications, as REST API, you need write all the API URL end point response.
 +  * using REST API allow your application to talk cross different application and difference device, and provide a safe gate to your important data handled by your application.
  
  • devwiki/python.1704570338.txt.gz
  • Last modified: 2024/01/06 19:45
  • by ying