zoukankan      html  css  js  c++  java
  • Python当中read(),readline(),和readlines()的区别

    当python进行文件的读取是,会遇到三个不同的函数,它们分别是read(),readline(),和readlines()。

    第一个函数read()

    一.read()

    这个函数将会从头到尾读取文件当中所有的内容,最后返回的结果为字符串

    二.readline()

    这个函数仅会读取一行的内容,返回的也是字符串,比较适合和文件读取当中的普通文件读取方法配合起来使用:

    f=open("123.txt","r")
    while True:
        file=f.readline()
        if file ==""
            break
       print(file)
    f.close()

    三.readlines()

    这个函数和read函数有一点相似,也是读取文件当中所有的内容,但是最后返回的是列表而不是字符串。

  • 相关阅读:
    startup毕业论文
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    LeetCode OJ
    install
    逻辑卷(lv)管理(LVM)
    mke2fs
    cat & 文件结束符
  • 原文地址:https://www.cnblogs.com/geeksongs/p/12598007.html
Copyright © 2011-2022 走看看