This example describes how Python file read and write operations interact with the Linux Shell variable command. Share to everyone for your reference. Specific as follows:
Python is easy to read and write to files, and the interaction variables with the Linux shell need to be converted to be used, which is more of a headache.
The code is as follows:
The code is as follows:
#coding =utf-8
#!/usr/bin/python
Import OS
Import time
#python执行linux命令
Os.system (': >./aa.py ')
#人机交互输入
S = Raw_input ("Input:")
os.environ[' s ']=str (s)
#把字符串S写入文件
Output = open ('./aa.py ', ' a ')
Output.write (S)
#关闭文件
Output.close ()
#python中的思考时间
Time.sleep (1)
#获取文件内容
f = open ('./aa.py ', ' R ')
Read = F.read ()
#变量间的转换
os.environ[' read ']=str (read)
Os.system (' $read ')
F.close ()
Var=os.popen (' Ifconfig '). Read ()
Print Var
Hopefully this article will help you with Python programming.