[英]Mute python fpdf.multi_cell in console
There's code part like:有如下代码部分:
for j, row in enumerate(data):
for datum in row:
line_height = lh_list[j] # choose right height for current row
if datum is row[0]:
pdf.set_font("Times", 'B', size=8)
pdf.multi_cell(col_width_name, line_height, datum, border=1, align='L', ln=3,
max_line_height=pdf.font_size, fill=True)
else:
pdf.set_font("Times", size=8)
pdf.multi_cell(col_width_value, line_height, datum, border=1, align='C', ln=3,
max_line_height=pdf.font_size)
pdf.ln(line_height)
it works fine, but because of multi_cell() method there are prints in console.它工作正常,但由于 multi_cell() 方法在控制台中有打印。 If there's a possibility to mute/turn off that printing?
如果有可能静音/关闭该打印?
Resolved by adding this code:通过添加此代码解决:
@contextmanager
def suppress_stdout():
with open(os.devnull, "w") as devnull:
old_stdout = sys.stdout
sys.stdout = devnull
try:
yield
finally:
sys.stdout = old_stdout
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.