day04学习笔记零散
# handle = open("test.txt")
print(r"D:\pytest\code\test.txt")
print("D:\pytest\code\test.txt")
handle = open("D:/pytest/code/test.txt", "r")
data = handle.read()
print(data)
handle.close()
handle = open("D:/pytest/code/test.txt", "r")
data = handle.readline() # 只读取一行
print(data)
data = handle.readlines() # 读取所有行
print(data)
handle.close()
# 分块读取
handle = open('test.txt', 'r')
for line in handle:
print(line)
handle.close()
handle = open('test.txt', 'r')
while True:
data = handle.read(1024)
print(data)
if not data:
break
# 读取二进制
#handle = open('day01.ipynb', 'rb')
# 写文件
handle = open('test.txt', 'w')
handle.write("这是一个测试!")
handle.close()
# with的使用
with open('test.txt') as file_handler:
for line in file_handler:
print(line)
# 异常使用
try:
file_handler = open("test.txt")
for line in file_handler:
print(line)
except IOError:
print("An IOError has occurred!")
finally:
file_handler.close()
以上是代码
以下是运行结果

text.txt
h
e
l
l
o
相关推荐
leetcode算法题主函数如何写-one_algorithm_one_day:每天一道算法题
leetcode算法题主函数如何写 one_algorithm_one_day 每天一道算法题 为了应付面试,开始写博客,准备开三个系列,第一个 JS算法系列,主要整理一些面试过程中常见的算法题 ; 第二个 ECMAScript规范解析,主要是想从ES规范的角度来解析JS代码的实际执行过程,只有真正懂得了底层干了什么,才能完全理解JS,而不需要记住很多零散的坑; 第三个 JS开源库代码阅读,通过阅读开源代码加深对JS的理解,同时积累大型项目开发的最佳实践。 本系列为 JS算法系列 [求数组中乘积最大的连续数] [判断单链表是否有环] [ES中对象在底层的储存方式,ES6 MAP/SET在底层是否采用hashmap/红黑树存储? EnumerateObjectProperties EnumerableOwnProperties] [最长上升子序列] # 1. 求两个已排序数组的中位数 There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two so
2-day-performance-tuning-guide.pdf
2-day-performance-tuning-guide.pdf
计算机二级考试Excel操作考试题.pdf
计算机二级考试Excel操作考试题.pdf
深度学习理念下思维导图在小学英语复习课中的应用.docx
深度学习理念下思维导图在小学英语复习课中的应用.docx
手绘女儿童教学课件模板.pptx
手绘女儿童教学课件模板


