20190904 Python 练习记录

>>> f=open('d:test.txt','r')
>>> f.read()
'adal啊的房间'
>>> f=close()
Traceback (most recent call last):
  File "<pyshell>", line 1, in <module>
NameError: name 'close' is not defined
>>> f.close()
>>> try:
    f=open('d:test.txt','r')
    print(f.read())
finally:
    if f:
        f.close()
adal啊的房间
>>> try:
    f=open('d:tes.txt','r')
    print(f.read())
finally:
    if f:
        f.close()
Traceback (most recent call last):
  File "<pyshell>", line 2, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'd:tes.txt'
>>> %Run thonny.py
Traceback (most recent call last):
  File "D:\thonny.py", line 2, in <module>
    f=open('d:tes.txt','r')
FileNotFoundError: [Errno 2] No such file or directory: 'd:tes.txt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\thonny.py", line 5, in <module>
    if f:
NameError: name 'f' is not defined
with open('d:test.txt','r') as f:
    print(f.read())

f=open('d:APP1.hex','r')
#with open('d:APP1.bin','r') as f:
#for line in f.readlines():
#print(f.readline()) #读一行
#print(f.readline()) #读一行
print(f.read(100))
f.close()


f=open('d:test.txt','r',encoding='gbk',errors='ignore')
print(f.read())
f.close()

f=open('d:test.txt','wb')
f.write(b'\x00\x01')
f.close()
f=open('d:test.txt','rb')
print(f.read())
f.close()   

with open('d:tes.txt','w') as f:
    f.write('zhodaognyoeuwoenpqgiquiogjo')
    f.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值