def f_sys(): ut.f_title("f_sys()") print(sys.argv) sys.path.append(os.path.join(os.path.dirname(__file__), '..')) for i in sys.path: print(i)
def f_write(fname): ut.f_title("f_write()") with open(fname, 'w') as f: f.write('123\n') f.write('456\n') f.write('abc\n') f.write('xyz\n')
def main(argv): funcs = ( "f_info", "f_new", "f_show", "f_resize", "f_crop", "f_cvt", "f_red", "f_np", "f_blur", "f_tile", "f_hist", "f_draw", ) if len(argv) == 1: selected = funcs else: selected = argv[1:] for i in selected: ut.f_title(i) eval(f"{i}()") cv2.waitKey()
def f_test(fname): ut.f_title("f_test()") if os.path.isfile(fname) == True: print("isfile: True") else: print("isfile: False") if os.path.isdir(fname) == True: print("isdir: True") else: print("isdir: False")
def f_shutil(fname): ut.f_title("f_shutil()") os.makedirs("_test_dir/a/b/c", exist_ok=True) if not os.path.exists("_test_dir2"): shutil.copytree("_test_dir", "_test_dir2") #os.rmdir("_test_dir") shutil.rmtree("_test_dir") shutil.copy("_test.txt", "_test_cp.txt") shutil.move("_test_cp.txt", "_test_mv.txt") os.remove("_test.txt") dir_name = os.environ['USERPROFILE'] print(f"dir_name: {dir_name}") os.system('ls -l') # deprecated import subprocess result = subprocess.run(('ls', '-l'))
def f_path(fname): ut.f_title("f_path()") path = "~/Desktop/" + fname print(f"path={path}") expanduser = os.path.expanduser(path) print(f"expanduser={expanduser}") abspath = os.path.abspath(expanduser) print(f"abspath={abspath}") dirname = os.path.dirname(abspath) print(f"dirname={dirname}") basename = os.path.basename(abspath) print(f"basename={basename}") #listdir = os.path.listdir(".") #print(f"listdir={listdir}") print(f"splitext={os.path.splitext(basename)}") join = os.path.join("a", "b", "c.txt") print(f"join={join}")
def main(argv): funcs = { "f_init", "f_array_1d", "f_array_1d_float", "f_array_2d", "f_array_3d", "f_array_op", "f_arange", "f_reshape", } if len(argv) == 1: selected = funcs else: selected = argv[1:] for i in selected: ut.f_title(i) eval(f"{i}()")
def main(argv): funcs = ( "f_input", "f_print", "f_print_old_style", "f_if", "f_for", "f_while", "f_func", "f_class", "f_subclass", "f_list", "f_range", "f_tuple", "f_set", "f_dict", "f_type", "f_zip", "f_color", "f_math", "f_exist", "f_func_object", "f_eval", ) if len(argv) == 1: selected = funcs else: selected = argv[1:] for i in selected: ut.f_title(i) eval(f"{i}()")
def f_read(fname): ut.f_title("f_read()") with open(fname, 'r') as f: for line in f: print(line.strip())
def f_chdir(dirname): ut.f_title("f_chdir()") print(f"os.getcwd(): {os.getcwd()}") os.chdir(dirname) print(f"os.getcwd(): {os.getcwd()}")
def f_glob(): ut.f_title("f_glob()") print(f"glob={glob.glob('./*')}")
def f_today(): ut.f_title("f_today()") today = dt.today() print(today) time_stamp = dt.now().strftime("%Y%m%d-%H%M%S") print(time_stamp)