您的位置:首页 > 产品设计 > UI/UE

简化ui文件转换写法

2015-12-29 15:14 429 查看
在命令行敲一串长的命令。枯燥麻烦。

#coding:utf-8
import sys
import os
import subprocess

if len(sys.argv) == 2:
#节省输入,不输入后缀
#直接使用參数的第2个值
file = sys.argv[1] + '.ui'
#检查输入文件是否存在
if not os.path.exists(file):
print('input file is not exited.')
exit(1)
#分离文件名称和扩展名
#本转换,和UI文件在同一文件夹
f, ext = os.path.splitext(file)
dist = f + '.py'
#运行的命令
cmd = 'pyuic4 ' + file + ' -o ui/' + dist
#使用subprocess模块,os.command也能够用
code = subprocess.call(cmd, shell=True)
#输出结果
if code == 0:
print('%s --> %s success.' % (file, dist))
else:
print('%s --> %s failure.' % (file, dist))


使用Python编写一个程序,随便练练语法。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: