python 统计字符串 实现tree命令

一、统计大小写字母,数字,其他字符

import io
import os
low=0
up=0
number=0
other=0
file=open("F:/py/train3/this.txt","r")
contend=file.read()

for x in contend:
	i=ord('x')   #  str 强制转换为 int

	if (i>=97)&(i<=129):
		low=low+1
	elif i>=65&i<97:
		up=up+1
	elif i>=0&i<=9:
		number=number+1
	else:
		other=other+1
print("low up number other")
print(low,end="   ")
print(up,end="   ")
print(number,end="   ")
print(other,end="   ")`在这里插入代码片`

二、用python实现tree 命令

import os 
import os.path

def tree(path,depth):
    if depth==0:
        print(path)
    filelist=os.listdir(path)
    for item in filelist:
        if '.git' not in item:       # git是隐藏文件名的扩展名,一般不可以访问,去掉会显示 premission error
            print('|  '*depth+'|__'+item)
            newpath=path+'\\'+item   #更新路径名,以进入下一次循环
            if os.path.isdir(newpath):
                tree(newpath,depth+1)

if __name__=='__main__':              #python 主函数开头是这么写的 
    filepath=input("input path  ")    #输入路径时,每进入一层路径 ,都要加\\
    tree(filepath,0)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值