Best Python code snippet using molecule_python
FindMaxFiles.py
Source:FindMaxFiles.py
...14 MB = 1024 * 102415 largest = nlargest(n, walk_files_and_sizes(start_at), key=lambda x: x[1])16 for path, size in largest:17 print(f'{size/MB} MB {path}')18def test_os_walk(dir_path: str):19 """20 https://docs.python.org/zh-cn/3/library/os.html#os.walk21 os.walk(file_path) è¿åçæå¨ç±»åï¼ä¸å
ç»; dirpath: æ ¹ç®å½è·¯å¾; dirnames: ç®å½ä¸ææçæ件夹; filenames: ç®å½ä¸ææçæ件夹22 """23 dir = os.walk(dir_path)24 print(type(dir))25 for dirpath, dirnames, filenames in dir:26 print(f'root: {dirpath}, dirnames: {dirnames}, files: {filenames}')27if __name__ == '__main__':28 """ start = time.perf_counter()29 largest_files(10, "C:/Windows")30 elapsed = time.perf_counter() - start31 print(f'{elapsed} seconds elapsed') """...
test_graphvizhelpers.py
Source:test_graphvizhelpers.py
...7 base = os.path.join(project_dir, "tmp")8 init_dir(base)9 yield base10 os.chdir(project_dir)11def test_os_walk(basedir):12 wt = os.path.join(basedir, 'test_os_walk')13 init_dir(wt)14 os.chdir(wt)15 write_file(wt, 'README.md', '# README please\n')16 write_file(wt, '.gitignore', '*~\n')17 write_file(wt, 'src/greeting', 'Hello, world!\n')18 write_file(wt, 'src/hello.pl', 'print(\"hello\")\n')19 assert os.path.exists(os.path.join(wt, 'src/greeting'))20 print('\n')21 for root, dirs, files in os.walk(wt, topdown=True):22 for name in files:23 print(os.path.join(".", name))24 for name in dirs:25 print(os.path.join(".", name))
test_os_walk.py
Source:test_os_walk.py
1import os2import shutil3def test_os_walk(): 4 os.makedirs('root')5 os.makedirs('root/first')6 os.makedirs('root/second')7 with open('root/first/hello.txt' , 'w') as f:8 f.write("hello test\n")9 with open('root/first/world.txt' , 'w') as f:10 f.write("world test\n")11 with open('root/second/hello.txt' , 'w') as f:12 f.write("hello test\n")13 with open('root/second/world.txt' , 'w') as f:14 f.write("world test\n")15 with open('root/tree.txt' , 'w') as f:16 f.write("tree test\n")17 for dirpath, dirnames, filenames in os.walk('root'):18 print(f'dirpath: {dirpath}, dirnames: {dirnames}, filenames: {filenames}')19 shutil.rmtree('root')20if __name__ == '__main__':...
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!!