300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > python中读取文本文件_Python三种读取txt文件方式

python中读取文本文件_Python三种读取txt文件方式

时间:2020-04-08 04:27:16

相关推荐

python中读取文本文件_Python三种读取txt文件方式

# -*- coding: utf-8 -*-

file =open('/Users/april_chou/Desktop/WorkSpace/Selenium/seleniumTest/test.txt','r')

context = file.read()

print('read格式:')

print(context)

file.close()

print()

file =open('/Users/april_chou/Desktop/WorkSpace/Selenium/seleniumTest/test.txt','r')

context = file.readlines()

contextLines =''

for i in context:

contextLines = contextLines + i

print('readlines格式:')

print(contextLines)

file.close()

print()

file =open('/Users/april_chou/Desktop/WorkSpace/Selenium/seleniumTest/test.txt','r')

contextLines =''

while True:

context = file.readline()

contextLines = contextLines + context

if len(context) ==0:

break

print('readline格式:')

print(contextLines)

file.close()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。