a = float('inf')
b = float('-inf')
a = True
b = False
if x is None:
pass
a, b = b, a
if 0 < a < 5:
pass
with open(file_path, 'rt', encoding='utf-8') as f:
for line in f:
print(line) # 末尾的\n会保留
import os
os.path.join('usr', 'lib', 'local')
import subprocess
# 如果外部命令返回值非0,则抛出subprocess.CalledProcessError异常
result = subprocess.check_output(['cmd', 'arg1', 'arg2']).decode('utf-8')
# 同时收集标准输出和标准错误
result = subprocess.check_output(['cmd', 'arg1', 'arg2'], stderr=subprocess.STDOUT).decode('utf-8')
# 执行shell命令(管道、重定向等),可以使用shlex.quote()将参数双引号引起来
result = subprocess.check_output('grep python | wc > out', shell=True).decode('utf-8')
欢迎光临 大内高手社区 (https://bbs.tedu.cn/) | Powered by Discuz! X3.4 |