Avatar of Kelly Garcia
Kelly GarciaFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Python Code

I am trying to understand the code below in python specifically the items inside the bracket. Are there example on using for (Something here, Something Here) in .... 

 for (dirpath, dirnames, filenames) in os.walk('community/Microsoft-365-Defender-Hunting-Queries'):

Open in new window

Python

Avatar of undefined
Last Comment
pepr
Avatar of Yujin Boby
Yujin Boby
Flag of India image

Above code will open the directory "community/Microsoft-365-Defender-Hunting-Queries"  in current folder, then get list of all directory and files inside it.

To understand, run following code

for (dirpath, dirnames, filenames) in os.walk("/path/to/some-folder"):
    print(dirpath, dirnames, filenames)

Open in new window


In above code, replace "/path/to/some-folder" with path to some folder name that is available on your computer.

Avatar of Kelly Garcia
Kelly Garcia
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

i am trying to understand how the bracket works, (dirpath, dirnames, filenames), will it do a loop on the dirpath first , then dirnames,..
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Python
Python

Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in other languages. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive set of standard libraries, including NumPy, SciPy, Django, PyQuery, and PyLibrary.

6K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo