Python file read and write operations and Linux shell Variable command Interactive execution method _python

Source: Internet
Author: User

This example describes the way Python file read and write operations interact with Linux shell variable commands. Share to everyone for your reference. Specifically as follows:

Python is easy to read and write files, and the Linux shell interaction variables need to be converted to use, which is more headaches.

The code is as follows:

Copy Code code 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

I hope this article will help you with your Python programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.