Python文件

  • 文件创建
  • f=open("t.txt","w")//没有写路径,默认当前路径下
    f.write("哈哈哈")
    import os
    src_file="D://a/a/tt.txt"
    fpath,fname=os.path.split(src_file)
    if  not os.path.exists(fpath):
        os.makedirs(fpath)
    f=open("D://a/a/tt.txt","w")
    f.write("哈哈哈")
    f.close()
    src="D://d/a/ttt.txt"
    f=open(src)
    c=f.read()
    print(c)
    文件读取
  • src="D://d/a/ttt.txt"
    f=open(src)
    #c=f.read()
    #c=f.readline()/读取一行
    c=f.readlines()//以列表形式读取所有数据
    print(c)['today is sunday\n', 'yest\n', 'very good']
    for i in f:
        print(i,end="")//迭代但是效率低

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值