zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Python 基本语法规则

Python规则 基本 语法
2023-09-11 14:14:44 时间

1. 抛异常

try:
    tree = ET.parse(xmlFilePath)
    root = tree.getroot()
except Exception as e:
    logging.warning ("parse UserPasswordConfigure.xml:%s", e)
    sys.exit()
finally:
    return data

 

2. 一次性执行命令行

import os

command = 'ping www.baidu.com ' #可以直接在命令行中执行的命令
r = os.popen(command) #执行该命令
info = r.readlines()  #读取命令行的输出到一个list
for line in info:  #按行遍历
    line = line.strip('\r\n')
    print line