python-文件操作3(读写文件的详细操作)

f=open('my-heart','r')
print(f.encoding)#返回字符编码
print(f.fileno())#返回操作系统的端口编号
print(f.seekable())#是否可以移动设备文件,一般二进制可以移动
print(f.writable())#是否可写
print(f.readable())#是否可读
print(f.flush())#刷新缓存内存到硬盘
print(dir(f.buffer))#


打印结果
-------------------------------------------------------------
cp936
3
True
False
True
None
['__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', 

'__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__lt__', '__ne__', '__new__', '__next__',
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_checkClosed', '_checkReadable',
'_checkSeekable', '_checkWritable', '_dealloc_warn', '_finalizing', 'close', 'closed', 'detach', 'fileno', 'flush', 'isatty', 'mode', 'name',
'peek', 'raw', 'read', 'read1', 'readable', 'readinto', 'readinto1', 'readline', 'readlines', 'seek', 'seekable', 'tell', 'truncate',

'writable', 'write', 'writelines']

实实刷新

f=open('my-hert2','w')
f.write("hello 1\n")
f.write("hello 2\n")
f.flush()#刷新写到硬盘上
f.write("hello 3\n")

进度条的打印

import sys,time
for i  in range(80):
    sys.stdout.write("#")#屏幕上输出#
    sys.stdout.flush()#刷新输出
    time.sleep(0.1)

打印结果
----------------------------------------------
########################################
 

猜你喜欢

转载自www.cnblogs.com/kezi/p/11946562.html