简化ui文件转换写法

在命令行敲一串长的命令。枯燥麻烦。


#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编写一个程序,随便练练语法。





原文地址:https://www.cnblogs.com/blfshiye/p/5085809.html