โดย jirawoot » 10/01/2020 12:10 pm
os.walk(directory) == >> จะเป็นการนำเอา directory มาทำเป็น json ผลที่ได้มาจะได้เป็น obj
สามารถศึกษาดูจาก == >> http://code.activestate.com/recipes/577879-create-a-nested-dictionary-from-oswalk/
ผลที่ได้ <generator object walk at 0x7f2a0b668780>
จากนั้น นำ obj มาวน loop โดย คำสั่ง for
ผลที่ได้เอามาจะมี 3 คือ
('test', ['test1', 'test2'], [])
('test/test1', [], ['test.py', 'zipfolder.py'])
('test/test2', [], ['test.py', 'zipfolder.py'])
ค่า 3 ค่านี้อยู่ใน root, directories, files ของ loop ด้านล่าง
for root, directories, files in os.walk(directory):
os.walk(directory) == >> จะเป็นการนำเอา directory มาทำเป็น json ผลที่ได้มาจะได้เป็น obj
สามารถศึกษาดูจาก == >> http://code.activestate.com/recipes/577879-create-a-nested-dictionary-from-oswalk/
ผลที่ได้ <generator object walk at 0x7f2a0b668780>
จากนั้น นำ obj มาวน loop โดย คำสั่ง for
ผลที่ได้เอามาจะมี 3 คือ
('test', ['test1', 'test2'], [])
('test/test1', [], ['test.py', 'zipfolder.py'])
('test/test2', [], ['test.py', 'zipfolder.py'])
ค่า 3 ค่านี้อยู่ใน root, directories, files ของ loop ด้านล่าง
for root, directories, files in os.walk(directory):