Let's say something else.
sudo to run commands with super privileges
Su switches to the root user
sudo su switches to root user with super privilege
That's the difference between them.
Read the file:
f = File (' Abc.txt ') is the same as F = open (' Abc.txt ') method.
f = File (' Abc.txt ', W) open a write file, open a read file by default without parameters.
Modes are:
R # # W # # a # rw # # RB # # WB # # ab##
F.read () returns a string
F.readlines () return list
F.readline () take out a row
F.close () Close file handle
F.flush () flush cache Instant Output
F.write () writes a string to a file
Shell color settings: \033[32;1m ... \033[0m
Import Fileinput
Line=fileinput.input (' Abc.txt ', inplace=1) #inplace的作用是文件指针返回到文件开头
Line=line.replace (' A ', ' a ') #将文件中的所有A替换成a
The pop () of the list takes the position as the parameter, and remove () takes the specific value as the parameter.
IS and = =.
Shell command: SSH [email protected] cmd
If the file name is a B, it can be entered by the command CD A\ B.
Definition of the default parameters for Python: Backward forward.
Join usage: ' + '. Join (a) # # A refers to a string or list
Pickle Module Usage:
# # Deposit data to pickle file # #
Import Pickle
a={"Name": "XXX", "Age": "Occupation": "IT",}
F=file (' abc.pkl ', ' WB ')
Pickle.dump (A,F)
F.close ()
# # Remove data from the Pickle file # #
F=file (' abc.pkl ', ' RB ')
A=pickle.load (f)
F.close ()
Re regular expression matching module:
Import re
P=re.compile (R ' Hello ')
Re.match # # Match start
P.findall # #找到所有匹配到该模式的内容
Re.sub (' [ABC] ', ' o ', Mark) # # Replaces all A, B, and C in Mark with O.
SSH related modules: Paramiko and Fabric
SYS module:
Import Sys
Print SYS.AGRV # # Sys.argv[0] is the program name.
Sys.path # #寻找路径
Python modules are generally placed under the/usr/lib/python2.7/dist-packages/directory.
Finish.
This article is from the "Blue Fin Dolphin" blog, please be sure to keep this source http://likunheng.blog.51cto.com/9527645/1571883
Python file interaction, module and pickle serialization, regular expression re module