python learning the seventh day - common file system module os, os.path, pickle

Module is a code segment available packaged, Py suffix, can be introduced into another program # use import

OS module: operting system OS #import os

os.chdir(path)
Change the current working directory
os.getcwd() Returns the current working directory

os.listdir(path)

List the name of the file or return path designated folder containing the folder.
os.mkdir(path[, mode]) Digital mode to mode to create a file called path of the folder. The default mode is 0777 (octal)
os.makedirs(path[, mode]) Recursive folder creation function. Like mkdir (), but all intermediate-level folders that you create needs to include subfolders.
os.open(file, flags[, mode])
Open a file, and set the desired options open, mode parameter is optional
os.remove(path) Delete the path for the path of the file. If the path is a folder, will throw OSError; see below rmdir () deletes a directory.
os.removedirs(path) Recursively delete the directory in which the directory is empty, can not contain files
os.rename(src, dst) Rename the file or directory from src to dst

os.renames(old, new)


Recursively renaming directories, files can be renamed.
os.rmdir(path) Delete empty directory path specified, if the directory is not empty, an exception is thrown a OSError
os.utime(path, times) Return to access and modify the file path specified time.

os.path modules:

os.path.abspath(path) Returns the absolute path
os.path.basename(path) Returns the file name
os.path.dirname(path) Returns the file path
os.path.exists(path) If the path path exists, returns True; path if the path does not exist, returns False
os.path.getatime(path) Returns the last access time (floating-point number of seconds), you can instead use local time localtime time module ()
os.path.getmtime(path) Returns last file modification time
os.path.getctime(path)  Returns the file path creation time
os.path.getsize(path) Returns the file size, file does not exist if it returns an error
os.path.isabs(path) Determine whether the absolute path
os.path.isfile(path) Determine whether the file path
os.path.isdir(path) Determine whether the directory path
os.path.islink(path) Determine whether the link path
os.path.ismount(path) Determine whether the path to the mount point # mount point directory entry is actually a disk file system in linux, similar to windows in C used to access different partitions:, D:, E: and so on letter
os.path.join(path1[, path2[, ...]])

The synthesis of a directory and file name path

Oskpthksmefaile (Pthl, Pth2) Determine whether the same file or directory
os.path.sameopenfile(fp1, fp2) Fp1 and fp2 point to determine whether the same file
os.path.samestat (stat1, stat2) Judgment stat tuple stat1 and stat2 point to the same file
os.path.split(path) The path is divided into dirname and basename, returns a tuple
os.path.splitdrive(path) Generally used in the windows, the drive and path returns a tuple
os.path.splitext(path) Split path, return path and file name extensions tuple
os.path.splitunc(path) The route into a mount point and file

pickle模块:将内容====>二进制====>保存(文件格式没有定性要求,一般为pkl)用来永久储存

存放:pickling

读取:unpickling

写入:pickle.dump(内容,文件(目的地))#打开文件,wb

读取:pickle.load(文件)#打开文件,rb

#字典操作分离,将字典存在硬盘上,而不是源码中

Guess you like

Origin www.cnblogs.com/code-fun/p/11758098.html