zoukankan      html  css  js  c++  java
  • 阿里巴巴测开(编程题)-输出目录下的文件(如果是目录要输出目录下的文件)

    循环方法:

    import os
    def allfile(basepath):
        for item in os.path.listdir(basepath):
            path = os.path.join(basepath, item)
            if os.path.isfile(path):
                print item
            else:
                allfile(path)

    不循环方法:

    import os
    
    for dirpath, dirnames, filenames in os.walk(basepath):
       
        for filename in filenames:
            print(filename)
    日行一善, 日写一撰
  • 相关阅读:
    git命令
    Linux基础知识手册
    Linux系统编程
    A
    Subsequences in Substrings Kattis
    G
    K
    K
    C
    E
  • 原文地址:https://www.cnblogs.com/xiyuan2016/p/14327637.html
Copyright © 2011-2022 走看看