php程序员学习python3学习第十四天
1,subprocess 执行命令行命令
# -*- coding: utf-8 -*- #subprocess 专门用于python执行命令行命令 import subprocess # subprocess.call('ipconfig') #执行系统命令,但拿不到结果,直接打印 # subprocess.check_call('ipconfig') #执行一条命令,如果执行状态为0,则返回0,否则抛出异常 ret = subprocess.check_output('ipconfig') #执行命令,如果状态码为0,则返回执行结果,否则抛出异常 print(ret) # subprocess.Popen() #执行复杂的命令
2,生成器,迭代器 生成器就是负责生成 field 迭代器就是负责逐个来取出__next__() 一个个取出
# -*- conding: utf-8 -*- #生成器和迭代器 #生成器 def xrange(n): start = 0 while True: if start > n: return yield start start += 1 #生成器只管生成,要使用还得使用迭代器 obj = xrange(5) #迭代器 逐个访问 n1 = obj.__next__() n2 = obj.__next__() print(n1,n2)
3,
-------------------------立码平天下------------------------------

浙公网安备 33010602011771号