(The detailed operation of the read and write files) 3 python- file operation

Open = F ( ' My-Heart ' , ' R & lt ' )
 Print (f.encoding) # Returns character encoding 
Print (f.fileno ()) # Returns the operating system port number 
Print (f.seekable ()) # whether mobile device file, generally a binary can move 
Print (f.writable ()) # is writable 
Print (f.readable ()) # is readable 
Print (f.flush ()) # flush the cache memory to the hard disk 
Print (dir ( f.buffer)) #
 

print the results
 ------------------------------------------ ------------------- 
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']

And indeed refreshing

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

Print progress bar

Import SYS, Time
 for i   in the Range (80 ): 
    sys.stdout.write ( " # " ) # output # on the screen 
    sys.stdout.flush () # flushed 
    the time.sleep (0.1 ) 

Print results
 ----- -----------------------------------------
 # ######## ###############################
 

 

 

Guess you like

Origin www.cnblogs.com/kezi/p/11946562.html