F=open (' Test '. txt ', ' w ')//write file
F=open (' Test.txt ', ' a ')//Append Write file
Read () disposable
ReadLine () reads a line
ReadLines () reads a line and retains it as a list inside
Seek (0) the file pointer points to the beginning
Tell () shows the current pointer position
OS and stat module get file: stat:
Import os
Import stat
Filestats = os. Stat ( ' test.txt ' )
FileMode = filestats [ stat. ST_mode ]
If stat. S_isreg ( filestats [ stat. ST_mode ] ):
print ' Regular file. '
Elif stat. S_isdir ( filestats [ stat. ST_mode ] ):
print ' Directory. '
Elif stat. S_islnk ( filestats [ stat. ST_mode ] ):
print ' Shortcut. '
Elif stat. S_issock ( filestats [ stat. ST_mode ] ):
print ' Socket. '
Elif stat. S_isfifo ( filestats [ stat. ST_mode ] ):
print ' Named pipe. '
Elif stat. S_isblk ( filestats [ stat. ST_mode ] ):
print ' Block special device. '
Elif stat. S_ISCHR ( filestats [ stat. ST_mode ] ):
print ' Character special device. '
Os.path:
Filestats = ' test.txt '
If os.path. Isdir ( filestats ):
print ' Directory. '
Elif os.path. Isfile ( filestats ):
print ' File. '
Elif os.path. Islink ( filestats ):
print ' Shortcut. '
Elif os.path. Ismount ( filestats ):
print ' Mount point. '
Python file Learning