linux 重定向到null失败,关于linux输出重定向(1>/dev/null)的一个疑惑

一个Python脚本 展示结巴分词结果 如下所示

test.py

# -*- coding: utf-8 -*-

import jieba

print("/".join(jieba.cut("hello world")))

print("/".join(jieba.cut("你好世界")))

运行该脚本 一切正常

python test.py

Building prefix dict from the default dictionary ...

Loading model from cache /var/folders/1k/p6dwx_0x28b6y752c1269hhw0000gn/T/jieba.cache

Loading model cost 0.398 seconds.

Prefix dict has been built succesfully.

hello/ /world

你好/世界

不想展示结巴相关的一些多余信息 于是通过Linux重定向的方式屏蔽这些信息 如下所示

python test.py 2>/dev/null

hello/ /world

你好/世界

于是可以==》 如果将正常输出屏蔽掉的话(1>/dev/null) 应该只会显示 python test.py 1>/dev/null = python test.py - python test.py 2>/dev/null 即

Building prefix dict from the default dictionary ...

Loading model from cache /var/folders/1k/p6dwx_0x28b6y752c1269hhw0000gn/T/jieba.cache

Loading model cost 0.398 seconds.

Prefix dict has been built succesfully.

但是发现实际输出的更多

python test.py 1>/dev/null

Building prefix dict from the default dictionary ...

Loading model from cache /var/folders/1k/p6dwx_0x28b6y752c1269hhw0000gn/T/jieba.cache

Loading model cost 0.379 seconds.

Prefix dict has been built succesfully.

Traceback (most recent call last):

File "test.py", line 10, in

print("/".join(jieba.cut("你好世界")))

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

这多出来的输出是怎么来的啊?怎么一开始执行 python test.py的时候就没有这个输出呢?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值