在Python中打印文件的目录

在Python中打印文件的目录,python,file,Python,File,它用于打印Python中某些文件的目录。但除此之外,我知道的很少。。。谢谢还有其他一些页面也有代码,但没有以“傻瓜指南”的形式对其进行充分解释。。所以我有点困惑。谢谢你的帮助。:我会试试看,希望这有帮助 import os for dirname, dirnames, filenames in os.walk('# I will have a directory here'): for filename in filenames: print (os.path.joi

它用于打印Python中某些文件的目录。但除此之外,我知道的很少。。。谢谢还有其他一些页面也有代码,但没有以“傻瓜指南”的形式对其进行充分解释。。所以我有点困惑。谢谢你的帮助。:

我会试试看,希望这有帮助

import os 

for dirname, dirnames, filenames in os.walk('# I will have a directory here'):
    for filename in filenames:
        print (os.path.join(dirname, filename))

请缩进你的代码。简要解释你想要达到的部分?你对文档有什么特别的问题吗?布莱,去问这个问题。谢谢,这真的很有帮助
import os 
#   vvvvvvv directory name of the current position in the walk (eg, /var then /var/log then /var/log/apache2, etc)
#            vvvvvvvv list (array) of sub directories
#                      vvvvvvvvv list (array) of files
for dirname, dirnames, filenames in os.walk('# I will have a directory here'): # loops through the directories list
    for filename in filenames: #loops through the files returned by the previous for loop
      print (os.path.join(dirname, filename)) # join the directory and the filename returning something like /var/log/dmesg.log