shanno吳

我与我周旋久,宁作我

Python小知识

2014-07-31

with open(pkglist, 'r') as fd:
   for line in fd.readlines():
	if not line.isspace():
	   cmdstr = "dpkg -i '%s'" % os.path.join(pkgpath, line.rstrip())
	   os.system(cmdstr)

将命令写在文件中,然后逐行读取文件中的命令执行。由于从文件中读取出来的行都带有换行符号,所以执行命令时会出错,这时候可以使用字符串str类的rstrip()方法将行末尾的空白字符剔除。

posted on 2014-07-31 18:36  shanno吴  阅读(386)  评论(0编辑  收藏  举报

导航