Python

Python GUI Frontend Options Comparison

2021-01-14. Category & Tags: Python, GUI, Desktop, Windows, Linux, Cross-Platfrom

Mainly for the (cross-platform) Python GUI frontend options. CEF (Chromium Embedded Framework). Pro: can use the same way of MVC thinking (modern html5); build-in chromium browser. Con: someone said it may need a little c++. PyQt (v5). Pro: big community, good doc (for c++). Con: c++ way of thinking, just the language is py (the official GUI tutorial lacks GUI screenshots!); pay for commercial usage; still often needs c++. Tkinter. Pro: build-in w/ py, big community. ...

Python-docx for MS Word

2021-01-12. Category & Tags: Python, MS Word, Pyhon-Docx, Docx

As the pyhon-docx does not want to provide a documentation (except some APIs) and the API doc web is really hard to browse and read, here are some small tips/demo tutorials to remember/avoid pits and falls. Please note: lib (0.8) provides only basic functions mainly for adding something (seems to be for test purpose). The main actions we do in a docx file should be done using MS API via this lib. ...

Python Convert Images to PDF

2020-03-18. Category & Tags: Python, Image, Picture, Pdf, Parallel

Two methods of downloading & converting pictures/images to a combined pdf file with parallel (multi-thread) from Mark Needham. f.write(img2pdf.convert(…)) [ref MarkHNeedham] from PIL import Image [ref DataToFish] Note: fpdf is not suggested as it canNOT support jpg natively. [ref stackoverflow]

Python Code Cookbook

2018-07-01. Category & Tags: Default Python, Reuse, Import, Include

See also: LearnPython, the Language Pandas # Get column_nr in pandas/numpy. if isinstance(X, pd.DataFrame): X_is_df = True row_nr = X.shape[0] column_nr = X.shape[1] if isinstance(X.columns, pd.core.index.MultiIndex): df_columns_is_multi_index = True else: df_columns_is_multi_index = False else: # non-DF X_is_df = False row_nr = np.shape(X)[0] column_nr = np.shape(X)[1] use dataframe directly against spark # lib Optimus from optimus import Optimus op = Optimus(master="local") df = op.create.df(<some data>) ... Sourcing/Importing # execfile or os.system # execute the other python file in place: ...

Python Code Reuse

2018-07-01. Category & Tags: Default Python, Reuse, Import, Include

execfile or os.system # execute the other python file in place: execfile("/path/to/my/lib/mylib.py") or: import os os.system("python /path/to/my/lib/mylib.py") import # import sys import os sys.path.append(os.path.abspath("/path/to/my/lib")) import mylib ref # See other methods here.

Learning Falcon

2018-01-13. Category & Tags: Python, Falcon, API

A great 5-video tutorial: 35minutes on YouTube (6 tomatoes / 2.5 hours for non-stop studing by coding). Author’s Github (py2), My Github (py3). Differences in my Github code: py3, not py2 using on_put() to test validity of input json from client using on_delete() to test params (just to test, should NOT be used in real-world) using another route /test2?x=1&y=3 to test params Usage in Nix: pip3 install falcon gunicorn gunicorn app:api # in the folder of app. ...

Python the Language (in case of)

2016-08-21. Category & Tags: Python, Environment, Virtualenv, Py, Py3, Lang, Language

Related: Learn Django python desktop GUI/frontend py code cookbook/reuse plot in py w pyvis Python in Win by MS official tutorial CN 用 Rust 让 numpy、scikit 和 pandas 加速 100 倍!开源 Weld 技术揭秘 PRE-INSTALL: CONDA VS. PIP # Pip requires apt. Thus, pip+apt. Pip chose to live together with apt (or other package manager) as apt is better at managing packages, especially when related to system. Some pip packages requires system (apt) to cooperate, such as uwsgi, graphviz, ffmpeg, gcc, python3-dev. ...

Learning Django

2016-08-18. Category & Tags: Python, Django, Web

(updated 2021.1) Related: Learn Python Ref: This is a combined learning note of: basic level sentdex’s youtube tutorial 2016, the corresponding video+text one is here. official tutorial which is still too complicated for new users, so better to use that after following this blog. middle level another tutorial: Django Tutorials for Beginners 2016 book “O’Reilly 2014 - Test-Driven Development with Python (django 1.7)”. official docs: DOCs.DjangoProject.com. all-in-one 3.8-hour video. Python Django Web Framework - Full Course for Beginners 2018 w/ Code (in sublime). ...

Cross-Read & -Write R, Py, Matlab, Binary Files

2016-06-01. Category & Tags: R, Binary, Mat, Matlab, Python, NumPy, Pandas

Note: feather-format is desigend to transfer data between Py & R [stackoverflow, feather-doc]. .FE # OBS: only for data.frame type, not even arrays. py (feather-format) # Requires: pip install feather-format. (OBS: feather-format NOT feather.) write: import numpy as np import pandas as pd df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]}, index=['one', 'two', 'three']) import feather feather.write_dataframe(df.reset_index(drop=True), 'df.fe') (though the df is created by pandas) read: import feather df = feather. ...

Jupyter

Category & Tags: Jupyter, Python

INSTALL # Anaconda Way # This is suggested for very new users to use a stable environment. It is NOT suitable for normal users / experienced programmers / engineers. for windows # Download Python 3 from Anaconda and install. From Windows “Start” menu, run “Jupyter” directly. (at least since v5.3.1) Old versions needs to run from navigator as below: anaconda for linux # Similar to win, for details, see here. ...