1
18
2014
2

python脚本

下面通过一个例子说明python脚本

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys

if len (sys.argv)!=5: 
	print"usage:./run.py *** *** *** ***,such as ./PCMSim system.ini.example ini/pcmsim-device.ini traces/k6_1.trc 1000 ..../"
	exit()
a=sys.argv[1]
b=sys.argv[2]
c=sys.argv[3]
d=sys.argv[4]

os.system("./PCMSim -s "+a+" -d "+b+" -t "+c+" -c "+d)

这个列子的脚本语言是将如下指令.

./PCMSim -s system.ini.example -d ini/pcmsim-device.ini -t traces/k6_1.trc -c 1000

简化成了./runpy system.ini.example ini/pcmsim-device.ini traces/k6_1.trc 1000(以上代码保存的文件名字为runpy)

a b c d 就是对应的第上一行的第1,2,3,4个参数,这个例子简化工作不明显。PCMSim后面跟的四个参数分为是系统配置、设备配置,trace,运行时钟周期。如果你在运行时,前三个参数是固定的,只需要测试不同的时钟周期的效果,则可以写成如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys

if len (sys.argv)!=2: 
	print"usage:./run.py ***,such as ./run.py 1000"
	exit()
a=sys.argv[1]

os.system("./PCMSim -s system.ini.example -d ini/pcmsim-device.ini -t traces/k6_1.trc -c "+a)

这样运行时直接./run.py 100就ok了.当然提醒一点在写完脚本后要记得做修改权限的操作即chmod 755 **。把文件改成可运行

 

下面看例二,在例二中,这个python的脚本就代替了八条命令的输入,你运行这个就直接输入./cpufreq.py 2395000就可以了,而不必坐在电脑前等上一条跑完在输入下一下。也就是说这一个脚本代替了八条语句的输入。

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys

if len(sys.argv)!=2:
	print "usage:./cpufreq.py xxx,such as ./cpufreq.py 2395000 "
	exit()
a=sys.argv[1]

for x in ['0','1','2','3']:
	os.system('xenpm set-scaling-maxfreq'+' '+x+' '+a)
	os.system('xenpm set-scaling-minfreq'+' '+x+' '+a)
Category: 脚本语言 | Tags: | Read Count: 1895
Avatar_small
依云 说:
2014年1月19日 13:03

这些脚本明显用 shell 来写更快更方便 =w=

Avatar_small
Bihar Board Model Pa 说:
2022年9月13日 18:21

Bihar State Vidyalay Pariksha Samiti, Patna Board (Bihar State School Examination Board) and others have designed and suggested the State Elementary Level Primary Education Class 3nd Grade study & learning material as Bihar Board 3rd Class Model Paper 2023 with Mock Test and Practice Questions. Bihar Board Model Paper Class 3 All Regional Students of Bihar Board can download the BSEB STD-3 Question Paper 2023 Pdf to All Languages and Subjects for SCERT & NCERT Syllabus students of Hindi Medium, English Medium and Urdu Medium Students Studding in Government & Private Schools of the State & Central Board.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com