第十天作业

import os

path = os.getcwd()
file_list = os.listdir(path)           #列出子目录、子文件夹
for filename in file_list:
    if filename.endswith("py"):
        print(filename,end="\t")


print("##########################################")

file_list2 = [filename for filename in os.listdir(path) if filename.endswith("py")]
for f in file_list2:
    print(f,end="\t")


def factorial(n):
    if n ==1:
        return n
    else:
        return n*factorial(n-1)
print(factorial(5))
import os
os.startfile(r"D:\Program Files (x86)\WeChat\WeChat.exe")
with open("e","r",encoding="utf-8") as f:
    lines = f.readlines()
    lines = [line.rstrip()+" #"+str(index+1)+"\n" for index,line in enumerate(lines)]
with open("e","w",encoding="utf-8") as f:
    f.writelines(lines)



with open("aa.png","rb") as f:
    with open("aa_copy.png","wb") as w:
        for line in f.readlines():
            w.write(line)

print("图谱拷贝完成.........")

with open("e","r",encoding = "utf-8") as f:
    print("文件名是:{0}".format(f.name))
    print(f.tell())
    print("读取内容:{0}".format(str(f.readline())))
print(f.tell)


import pickle
a1 = "张三"
a2 = 123
a3 = [10,20,30]
with open("data.dat","wb") as f:
    pickle.dump(a1,f)
    pickle.dump(a2,f)
    pickle.dump(a3,f)

with open("data.dat","rb") as f:
    b1 = pickle.load(f)
    b2 = pickle.load(f)
    b3 = pickle.load(f)
    print(b1)
    print(b2)
    print(b3)

try:
    f = open(r"D:\test01.txt","w")
    strs = ["aa","bb","cc"]
    f.writelines(strs)
finally:
    f.close()
s = ["张三\n","李四\n","王五\n"]
with open(r"D:\test01.txt","w") as f:
    f.writelines(s)

with open(r"e","r",encoding="utf-8") as f:
    str = f.read()
    print(str)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值