Best Python code snippet using localstack_python
cleaner.py
Source:cleaner.py
...6# @blog : https://blog.csdn.net/hongbin_xu7# @File : cleaner8# @Software: PyCharm9from pathlib import Path10def rm_dir(dir_path, silent=True):11 p = Path(dir_path).resolve()12 if (not p.is_file()) and (not p.is_dir()) :13 print('It is not path for file nor directory :',p)14 return15 paths = list(p.iterdir())16 if (len(paths) == 0) and p.is_dir() :17 p.rmdir()18 if not silent : print('removed empty dir :',p)19 else :20 for path in paths :21 if path.is_file() :22 path.unlink()23 if not silent : print('removed file :',path)24 else:25 rm_dir(path)26 p.rmdir()27 if not silent : print('removed empty dir :',p)28def clean():29 ckpt_dir = Path('./checkpoints')30 log_dir = Path('./logs')31 summary_dir = Path('./summary')32 rm_dir(ckpt_dir)33 rm_dir(log_dir)34 rm_dir(summary_dir)35 print('{} removed!'.format(ckpt_dir))36 print('{} removed!'.format(log_dir))37 print('{} removed!'.format(summary_dir))38 print('[*] Cleaning finished!')39if __name__ == '__main__':...
move_img_files.py
Source:move_img_files.py
1import os2import shutil3def mv_files(dir):4 count = 05 for root, dirs, files in os.walk(dir):6 for fname in files:7 full_fname = os.path.join(root, fname)8 if 'jpg' in fname:9 target = full_fname.split('/')10 idx = full_fname.find(target[-1])11 rename_dir = os.path.join(full_fname[:idx],target[3] + '_' + str(count) + '.jpg')12 moved_dir = os.path.join(dir,target[3],target[3] + '_' + str(count) + '.jpg')13 os.rename(full_fname, rename_dir)14 shutil.move(rename_dir,moved_dir)15 count += 116#17# def rm_empty_folder(dir):18# for root, dirs, files in os.walk(dir):19# rm_dir = root.split('/')20# # print(len(rm_dir))21# # print(rm_dir)22# if len(rm_dir) > 6:23# rm_dir = os.path.join(rm_dir[0],rm_dir[1],rm_dir[2],rm_dir[3])24# print(rm_dir)25if __name__ == '__main__':26 mv_files('./sample_data/image/')...
remove_links.py
Source:remove_links.py
1import os2import sys3rm_dir = sys.argv[1]4files = os.listdir(rm_dir)5for f in files:6 filename = os.path.join(rm_dir, f)7 if os.path.islink(filename):8 print 'Removing', filename...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!