Tips¶
- You can use Convert curl syntax to Python, Node.js, PHP, R or curlconverter to convert CURL commands to Python requests code.
Get All Tags of a Docker Image¶
Construct pandas DataFrames in Python
Unpacking Assignment in Python
The unpacking assignment assigns elements of a tuple/list to variables at once.
Runtime Paths in Python
__file__
is the path of the Python script.
Note that if you make a sybolic link to a Python script and run the symbolic link,
then __file__
is the path of the symbolic link.
Of course, you can use os.path.realpath
to get real path of files.
pathlib.Path …
Select Columns from Structured Text Files
Python pandas
My first choice is pandas in Python. However, below are some tools for quick and dirty solutions.
q
q -t -H 'select c1, c3 from file.txt'
cut
cut -d\t -f1,3 file.txt
awk
awk -F'\t' '{print $1 "\t" $3}' file.tsv
Note: neither cut …
Get Group Names on Linux/Unix
Linux
-
Get information of the
staff
group.$ getent group staff staff:x:20:
-
Get group ID of the
staff
group.$ getent group staff | cut -d: -f3 20
Mac
-
Get information of the
staff
group.$ dscl . -read /Groups/staff
-
Get group ID of the
staff
group.$ dscl . -read /Groups/staff | awk …