文件读写
一、读取文件
with open('pass.txt','r') as f:
content = f.read() //一次读取所有内容
print(content)
with open('pass.txt','r') as f: //将所有内容读取到一个列表中
for line in f.readlines(): //循环列表
if line.strip() == '333333': //此时line为 '333333\n',line.strip()去除掉换行
print('success')
break
else:
continue
else:
print('error')
二、写入文件
with open('pass.txt','a') as f:
f.write('\nhello1\n')
f.write('hello2\n')
f.write('hello3\n')