余额宝转入时间,新概念2,陈海基
不想在python中调用shell,需要实现一个类似linux tree命令的功能[root@python_test OcApi]# tree . |-- OCenter | |-- Lib | | |-- Mysql.php | | `-- Think.php | |-- Model | | |-- Base.php | | `-- User.php | `-- OCenter.php `-- oc.php
#coding:utf-8 import os def list_files(startpath): for root, dirs, files in os.walk(startpath): level = root.replace(startpath, '').count(os.sep) if not level: continue dir_indent = "| " * (level-1) + "|-- " file_indent = "| " * level + "|-- " print('{}{}'.format(dir_indent, os.path.basename(root))) for f in files: print('{}{}'.format(file_indent, f)) list_files('/root/OcApi')
输出结果
[root@python_test xx]# /usr/local/python-3.6.2/bin/python3 xxxx |-- OCenter | |-- OCenter.php | |-- Lib | | |-- Think.php | | |-- Mysql.php | |-- Model | | |-- User.php | | |-- Base.php
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
python求numpy中array按列非零元素的平均值案例
网友评论