Python file read and write operations interactively executed with Linux shell variable commands

  • 2020-04-02 14:29:10
  • OfStack

This article illustrates how to interactively execute python file read and write operations with Linux shell variable commands. Share with you for your reference. The details are as follows:

Python is easy to read and write to files, and the Linux shell's interactive variables need to be converted to use, which is a headache.

The code is as follows:


#coding=utf-8
#!/usr/bin/python
import os
import time
#python perform linux The command
os.system(':>./aa.py')
# Human-computer interactive input
S = raw_input("input:")
os.environ['S']=str(S)
# Put the string S Written to the file
output = open('./aa.py','a')
output.write(S)
# Close the file
output.close()
#python Thinking time in
time.sleep(1)
# Get file contents
f = open('./aa.py','r')
read = f.read()
# Transformation between variables
os.environ['read']=str(read)
os.system('$read')
f.close()
var=os.popen('ifconfig').read( )
print var

I hope this article has helped you with your Python programming.


Related articles: