Fill in missing codes
DEF print_directory_contents ( sPath ): "" " This function accepts as input the name of the folder parameter returns the files in the folder path . comprising a path and file folder " "" # supplementary code
answer
def print_directory_contents(sPath):
import os for sChild in os.listdir(sPath): sChildPath = os.path.join(sPath,sChild) if os.path.isdir(sChildPath): print_directory_contents(sChildPath) else: print sChildPath
With particular attention to the following points:
- To unify naming conventions. If the sample code can be seen in naming, which follow the existing norms.
- Recursive function needs a recursive and terminates. Make sure you understand the principles involved, otherwise you will face endless call stack (callstack).
- We use the
os
module to interact with the operating system, but can be done interactively cross-platform. You can write the codesChildPath = sPath + '/' + sChild
, but this on a Windows system error. - Familiar with the basic module is very valuable, but do not back down Xiangponaodai all, remember that Google is your job mentor.
- If you do not understand the intended function of the code, it is daring to ask questions.
- Adhere to the KISS principle! Keep it simple, but the brain can understand!
- This article first appeared in Python black hole net , blog sync with the new park