Python_读文件的三个方法

2021-11-18  本文已影响0人  Gakki0725
作者:Gakki

1. read()

with open("1.txt", 'r') as file_object:
    # 读取 10 个字节
    get_text = file_object.read(10)
    print(type(get_text))
    print(get_text)

2. readline()

with open("1.txt", 'r') as file_object:
    get_text = file_object.readline()
    print(type(get_text))
    print(get_text)

3. readlines()

with open("1.txt", 'r') as file_object:
    for line in file_object.readlines():
        print(line)
上一篇下一篇

猜你喜欢

热点阅读