小编lzu*_*tao的帖子

为什么python2和python3中的print输出与同一个字符串不同?

在python2中:

$ python2 -c 'print "\x08\x04\x87\x18"' | hexdump -C
00000000  08 04 87 18 0a                                    |.....|
00000005
Run Code Online (Sandbox Code Playgroud)

在python3中:

$ python3 -c 'print("\x08\x04\x87\x18")' | hexdump -C
00000000  08 04 c2 87 18 0a                                 |......|
00000006
Run Code Online (Sandbox Code Playgroud)

为什么"\xc2"这里有字节?

编辑:

我认为当字符串具有非ascii字符时,python3会将字节附加"\xc2"到字符串.(正如@Ashraful Islam所说)

那我怎么能在python3中避免这种情况呢?

python unicode utf-8

8
推荐指数
2
解决办法
1232
查看次数

我如何实际将"\n\r"写入环境变量?

我尝试过命令替换,但用空格替换'\n'

$ export GREENIE="$(python -c 'print "\n\r"*4')"
$ echo $GREENIE |hexdump
0000000 200d 200d 200d 0a0d                    
0000008
$ 
Run Code Online (Sandbox Code Playgroud)

我只需要这样:

$ echo $GREENIE |hexdump
00000000  0a0d 0a0d 0a0d 0a0d
00000008
$
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

bash environment-variables

2
推荐指数
1
解决办法
772
查看次数

标签 统计

bash ×1

environment-variables ×1

python ×1

unicode ×1

utf-8 ×1