Python

Python基础(33) - read,readline和rea

2020-03-08  本文已影响0人  xianling_he

Read方法的使用

f = open('C:\\PyTest\\Selenium_OpenSchools\\test_selenium\\综合学习\\files\\temp.txt')
print(type(f))
print(f.read())
hexianling.png
f = open('C:\\PyTest\\Selenium_OpenSchools\\test_selenium\\综合学习\\files\\temp.txt')
print(type(f))
print(f.read(6))
hexianling.png

Read 配合seek使用

f = open('C:\\PyTest\\Selenium_OpenSchools\\test_selenium\\综合学习\\files\\temp.txt')
print(type(f))

print('-'*20)
f.seek(2)  #从第2个字符开始

print(f.read(4)) #往后4个字符串输出
hexianling.png

Readline方法的使用

f = open('C:\\PyTest\\Selenium_OpenSchools\\test_selenium\\综合学习\\files\\temp.txt')
print(type(f))

print('-'*20)
print(f.readline())
print(f.readline())
hexianling.png

Readline方法的使用,使用参数N限制输出字符串

f = open('C:\\PyTest\\Selenium_OpenSchools\\test_selenium\\综合学习\\files\\temp.txt')
print(type(f))
print(f.readline(3))
hexianling.png
f = open('C:\\PyTest\\Selenium_OpenSchools\\test_selenium\\综合学习\\files\\temp.txt')
print(type(f))
print(f.readline(30))
hexianling.png

Readlines方法的使用

f = open('C:\\PyTest\\Selenium_OpenSchools\\test_selenium\\综合学习\\files\\temp.txt')
print(type(f))

print(f.readlines())
hexianling.png
f = open('C:\\PyTest\\Selenium_OpenSchools\\test_selenium\\综合学习\\files\\temp.txt')
print(type(f))

print(f.readlines(3))
hexianling.png
f = open('C:\\PyTest\\Selenium_OpenSchools\\test_selenium\\综合学习\\files\\temp.txt')
print(type(f))

print(f.readlines(30))
hexianling.png

加油 2020-3-8

上一篇 下一篇

猜你喜欢

热点阅读