scriptlib

This commit is contained in:
Jana Dönszelmann 2025-08-25 14:04:31 +02:00
parent ddb92ea0c5
commit 816c61985d
No known key found for this signature in database
5 changed files with 67 additions and 19 deletions

50
scriptlib/scriptlib.py Normal file
View file

@ -0,0 +1,50 @@
from math import *;
import numpy as np
from pathlib import Path
import subprocess
import os
from pprint import pprint
from itertools import *
Path.__repr__ = lambda i: f"p'{str(i)}'"
kilo = 1000
mega = 1000 * kilo
giga = 1000 * mega
tera = 1000 * giga
peta = 1000 * tera
b = 1
kib = 1024
mib = 1024 * kib
gib = 1024 * mib
tib = 1024 * gib
pib = 1024 * tib
inch = 0.0254
yard = 0.9144
def cwd():
return Path.cwd()
def ls(d = None):
if d is None:
d = cwd()
return list(Path(d).iterdir())
def glob(expr):
return list(cwd().glob(expr))
def run(cmd, only_stdout=True):
res = subprocess.run(cmd, capture_output=True, text=True, shell=True)
if only_stdout:
return str(res.stdout)
else:
return res
def cat(file):
return open(file, "r").read()
print_ = print
print = pprint