返回列表 发帖

[技术讨论] Python脚本获取当前目录下有哪些文件夹

import os
for i in os.listdir('.'):
    if os.path.isdir(i):
        print iCOPY
import os
cmd = "dir /b /ad"
for i in os.popen(cmd).readlines():
    print i,COPY
import os
for root, dirs, files in os.walk('.'):
    for i in dirs:
        print i
    breakCOPY
试着写了几个,总感觉不够优雅,求大湿指点。

print 早就更新了,
print(i)
print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout)
   
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file: a file-like object (stream); defaults to the current sys.stdout.
    sep:  string inserted between values, default a space.
    end:  string appended after the last value, default a newline.COPY

TOP

回复 2# ivor


你用的Python3是吧,其实还是有很大一部分人在用Python2的,包括我。

TOP

学习了,,,我感觉代码已经比较优雅了。。
问题解决后,请在标题前面注明[已解决],并给回答者加分——化繁为简,提高工作效率!

TOP

返回列表