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)