zoukankan      html  css  js  c++  java
  • Python基础-day08-文件的操作

    • 文件的基本操作:打开,读取,关闭

    打开文件open(参数1,参数2,encoding)

    参数1:文件名

    参数2:读取模式

    f=open("a.txt",mode="r",encoding="utf-8")
    content=f.read() //读取所有内容
    firstline=f.readline()//读取第一行
    print(content) f.close()
    •    指定路径读取
    p=open(r"D:python27day01-HellowordHelloWorld.py",mode="r",encoding="utf-8")
    print(p.readlines())
    • 文件模式

    r  -读取

    a -追加

    w-覆盖写入

    • with语句,不用关闭文件
    with open("a.txt",mode="r",encoding="utf-8") as f:
        print(f.read())
  • 相关阅读:
    UVA 1590 IP Networks
    UVA 12108
    HDUOJ 1042 N!
    UVA201 Squares
    UVaOJ 1339
    UVaOJ 202
    UVaOJ 100
    UVaOJ 10340
    第五章 跳跃表
    第四章 字典
  • 原文地址:https://www.cnblogs.com/majinjin/p/14981791.html
Copyright © 2011-2022 走看看