Import Tab #支持tab补全
Import Fileinput # supports file-based string substitution
For line in Fileinput.input (' filepath ', inplace=1): #1表示完成后回到行首
Line=line.replace (OLDSTR,NEWSTR)
Import OS
Get the current working directory, which is the directory path of the current Python script work: OS.GETCWD ()
Returns all files and directory names in the specified directory: Os.listdir ()
function to delete a file: Os.remove ()
Delete multiple directories: Os.removedirs (R ' C:\python ')
Detects whether the given path is a file or a directory: Os.path.isfile () Os.path.isdir ()
Determine if it is an absolute path: Os.path.isabs ()
Determine if the path exists: os.path.exists ()
Returns the directory name and file name of a path: Os.path.split ()
Detach extension: Os.path.splitext ()
Get path name: Os.path.dirname ()
Get file name: Os.path.basename ()
Run shell command: Os.system ()
Read and SET Environment variables: os.getenv () and os.setenv ()
Gives the line terminator used by the current platform: Os.linesep ()
Determine the current platform for Python: os.name for Windows, he is ' NT ', and for unix/linux users, he is ' POSIX '
Renamed: Os.rename (old,new)
Create a multilevel directory: Os.makedirs (R ' c:\python\test ')
Create a single directory: Os.mkdir ("Test")
Get file attributes: Os.stat (file) or Os.lstat (file)
>>> os.lstat (' D:/media ')
Nt.stat_result (st_mode=16895, st_ino=0l, st_dev=0, st_nlink=0, St_uid=0, St_gid=0, st_size=0l, St_atime=1411793385L, st_mtime=1411793385l, st_ctime=1390222253l)
>>> os.stat (' D:/media ')
Nt.stat_result (st_mode=16895, st_ino=0l, st_dev=0, st_nlink=0, St_uid=0, St_gid=0, st_size=0l, St_atime=1411793385L, st_mtime=1411793385l, st_ctime=1390222253l)
>>>
Modify file permissions and timestamps: Os.chmod (file)
Terminate current process: Os.exit ()
Get File Size: os.path.getsize (filename)
File operation:
Os.mknod (' Test.txt ') #创建空文件
F=open (' Test.txt ', ' R ') # R W A
F.read ([size]) #size为读取的长度, in bytes
F.readline ([size])
F.readlines ([size])
F.
Python Learning Note 2 python file processing