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. Con: //TODO.
  • electron / nwjs (bad word of mouth) /javafx / swiftui / flutter : Pro: quick to develop. Con: using node.js, too slow to run and to learn. // though it is possible for experts to make VSCode using electron.
  • wxPython: Pro: small-to-middle-size community… Con: too new, few people.

ref: zhihu & youtube

...

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.
  • copy.deepcopy(.) should be used within the lib, not applying on MS objects.

Plot in Python, Visualization wtih pyvis

2019-07-05. Category & Tags: Jupyter, Python, Visualisation, Matplotlib, PyViz, Plot

Books & Docs #

  • Seaborn tutorial & gallary
  • OReilly 2017 - [easy to find common examples] Python Data Science Handbook
  • Packt 2015 - [nice code grammar] Python Data Visualization Cookbook, 2nd Ed. (Igor Milovanovic)
  • Packt 2015 - [rich & various content] Mastering Python Data Visualization
  • Packt 2015 - [advanced nice plots & deployments] Mastering matplotlib (D.M. McGreggor)
  • [Very bad composition] Packt 2018 - Matplotlib for Python Developers - 2nd Ed (by Allen Yu, Claire Chung)

Overview of Libs #

Python Data Visualisation Landscape

...

Python Code Cookbook

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

See also:

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.py

Usage in Win (tested in bash sub system):

...

Python the Language (in case of)

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

Related:

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:

Update: newly tested w/ Ubuntu 1804 + py 3.8.5 + django 3.1.

...

Jupyter

2016-08-06. 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.

...