python/Django下读写文件,等待,调用shell命令等技术总结
2011-11-22 20:19
1226 查看
一、python/Django 写文件
file_object = open('/opt/ result.txt','w')
file_object.write(gg)
file_object.close()
打开/opt目录下的result.txt文件,并将字符串gg写入result.txt文件
二、python/Django 读文件
file_object = open('/opt/ test.py')
try:
gg = file_object.read()
finally:
file_object.close()
打开/opt目录下的test.py文件,将文件内容赋值给gg,作为一个长字符串
三、python/Django 程序中等待
import time
time.sleep(5)
四、python/Django 调用shell命令
import os, sys
cmdd = "python /opt/test.py"
os.system(cmdd)
或者
import os, sys
cmdd = "python /opt/test.py "
gg = os.popen(cmdd).read()
或者
import subprocess
process = subprocess.Popen(['service', 'httpd', 'restart'])
或者
import subprocess
r = subprocess.call("service httpd restart 1>$HOME/out 2>$HOME/error",Shell=True)
file_object = open('/opt/ result.txt','w')
file_object.write(gg)
file_object.close()
打开/opt目录下的result.txt文件,并将字符串gg写入result.txt文件
二、python/Django 读文件
file_object = open('/opt/ test.py')
try:
gg = file_object.read()
finally:
file_object.close()
打开/opt目录下的test.py文件,将文件内容赋值给gg,作为一个长字符串
三、python/Django 程序中等待
import time
time.sleep(5)
四、python/Django 调用shell命令
import os, sys
cmdd = "python /opt/test.py"
os.system(cmdd)
或者
import os, sys
cmdd = "python /opt/test.py "
gg = os.popen(cmdd).read()
或者
import subprocess
process = subprocess.Popen(['service', 'httpd', 'restart'])
或者
import subprocess
r = subprocess.call("service httpd restart 1>$HOME/out 2>$HOME/error",Shell=True)
相关文章推荐
- 【python中调用shell命令使用PIPE】使用PIPE作为stdout出现假卡死的情况——将stdout重定向为输出到临时文件
- python调用shell命令的方法
- python调用shell命令之三慷慨法
- java 中调用window系统中的文件,或者执行命令(shell、.CMD、.EXE)并获取返回值
- python 调用shell命令的方法
- 使用终端shell命令批量修改一个文件下的所有文件的读写权限
- Python中如何调用shell命令
- python文件读写操作与linux shell变量命令交互执行
- python文件读写操作与linux shell变量命令交互执行的方法
- Python调用shell命令
- Python下调用Linux的Shell命令的方法
- paip.执行shell cmd 命令uapi java php python总结
- python 调用shell命令三种方法 分类: python基础学习 python Module 2014-01-13 14:13 239人阅读 评论(0) 收藏
- python——Django项目开发:配置项目/static/路径,调用css、img、js等静态文件
- python 调用shell命令的方法
- python调用shell命令小结 推荐
- 在独立的python文件调用django api
- Nodejs中调用系统命令、Shell脚本和Python脚本的方法和实例
- [python]如何调用shell命令
- Python下调用Linux的Shell命令