Tips and Traps¶
The command-line tool of some (e.g., network) applications might be slow to authenticate. If you use pexect to automate such a command-line tool, it is best to wait for sometime after sending password using
child.sendline(passwd)
. If the authentication has ouput on both success and failure, a smart way is to wait for the success or failure message to come out.
IPython Is the Best Shell
IPython is the Best Shell!
-
Use IPython as much as possible.
- IPython has virtues of both shell and Python.
- You should avoid using shell scripts for complicate tasks any way.
-
If you do want to use a Unix/Linux shell, I'd suggest you stick to Bash unless Linux distributions start …
Python Alternatives to Shell
Working with Spreadsheet in Python
It is suggested that you avoid using Excel files (or other spreadsheet tools) for storing data. Parquet file is currently the best format for storing table-like data. If you do want to interact and manipulate your data using Excel (or other spreadsheet tools), dump your data into CSV files and …
Expose Local Services to Public Using ngrok
You can expose a local service to public using ngrok
.
Follow instructions in the
official documentation of ngrok
to setup ngrok
.
-
Install ngrok.
sudo snap install ngrok
-
Login to https://ngrok.com to identify your ngrok token.
-
Connect your account following instructions.
ngrok config add-authtoken your_token
-
Start a http tunnel …
Extracting PDF Pages Using the Python Package PyPDF2
The Python package PyPDF2 can be used to extract pages from a PDF file. The function aiutil.pdf.extract_pages is a wrapper over PyPDF2 which makes it even easier to extract pages from a PDF file.