Python
Lambda
https://medium.com/better-programming/how-to-use-lambda-expressions-in-python-a96330b513d4
Lambda Example - 模擬 switch
在Python中缺少其它語言中的switch陳述句,以下結合字典物件與lambda模擬switch的示範
score = int(input('請輸入分數:'))
level = score // 10
{
10 : lambda: print('Perfect'),
9 : lambda: print('A'),
8 : lambda: print('B'),
7 : lambda: print('C'),
6 : lambda: print('D')
}.get(level, lambda: print('E'))()在上例中,字典物件中的值的部份是lambda所建立的函式物件,你使用get()方法指定鍵,如果有符合的鍵,就傳回對應的函式物件並執行,否則就傳回get()第二個引數所指定的函式並執行,這模擬了switch中default的陳述。
List (Slicing)
Import
Python的import陷阱
https://pyliaorachel.github.io/blog/tech/python/2017/09/15/pythons-import-trap.html
Flask
Get parameter
Input:
http://127.0.0.1:5000/?paramStr=test123中文
Output:
Allow Cross-origin AJAX
Handling Cross Origin Resource Sharing (CORS), making cross-origin AJAX
Simple Usage
https://flask-cors.readthedocs.io/en/latest/
Flask-Session
Managing Session Data in Flask with Flask-Session & Redis
https://hackingandslacking.com/managing-flask-session-variables-f4c5ccef54c0
run with https
validate https cert
https://bits.mdminhazulhaque.io/python/run-flask-app-with-let's-encrypt-ssl-certificate.html
I got errno=0 which means Flask is working fine with SSL. :D
PEP8 standards - Style Guide
Logging
Good logging practice
Output:
change the logger level to DEBUG and see the output again
Output:
logging 教學
Numpy
Tips
Pandas
Tips
Tips
Determine if variable is defined
'a' in vars() or 'a' in globals()
if you want to be pedantic, you can check the builtins too
'a' in vars(__builtins__)
Code Example
list of dictionaries search
min(None, x)
https://stackoverflow.com/questions/6254871/python-minnone-x
https://stackoverflow.com/questions/46025724/getting-max-value-from-a-list-with-none-elements
Get Max Value in Dict
https://stackoverflow.com/questions/268272/getting-key-with-maximum-value-in-dictionary
Tools
Visual Studio Code
https://code.visualstudio.com/
Top 10 Visual Studio Code extensions for Python development
8 VS Code Extensions You Might Love
https://medium.com/better-programming/8-vs-code-extensions-you-might-love-eba03d85fd4f
Setting Sync
https://marketplace.visualstudio.com/items?itemName=Shan.code-settings-sync
Kite
Automated RESTful API testing
Tavern
https://taverntesting.github.io/examples
Protect code
Troubleshoot
Mac OS X: ValueError: unknown locale: UTF-8
add these lines to your ~/.bash_profile
ERROR: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is
FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type. from ._conv import register_converters as _register_converters
Problem: h5py issue (2.7.1
Solution: upgrade h5py (2.9.0)
17個新手常見的Python運行時錯誤
https://www.oschina.net/question/89964_62779
ERROR: ImportError: cannot import name 'Flask'
Problem: error while import 'flask'
Solution: The reason is your python file name is 'flask' in same directory.
Python的中文編碼處理
Library
Python library 集合
https://www.zhihu.com/question/24590883
https://kknews.cc/zh-hk/other/rb2m5m4.html
Reference:
Deploying a Machine Learning Model as a REST API
https://towardsdatascience.com/deploying-a-machine-learning-model-as-a-rest-api-4a03b865c166
Flask設置返回json格式數據
Multi-processing
Web Scrapping
Parse Youtube link to iframe embeded code
https://micawber.readthedocs.io/en/latest/
Html2text - Convert HTML to Markdown-formatted text
http://alir3z4.github.io/html2text/
https://github.com/Alir3z4/html2text/blob/master/docs/usage.md
Audio Steaming
Last updated

