The previous post was for commands Unix. This post is about the Python commands I use or Google frequently.
To find the absolute path of the directory of the current file being executed -
abs_path = os.path.dirname(os.path.realpath(file))
To copy a file from source to destination (using shutil)-
from shutil import copyfile copyfile(src, dst)
To copy a file or directory from source to destination (using shutil)-
from shutil import copy copy(src, dst)
To create a directory if it doesn’t exist -
import os if not os.path.exists(directory): os.makedirs(directory)
To write a JSON to a file -
import json with open(‘data.json’, ‘w’) as f: json.dump(data, f)