查看string.maketrans的输出

时间:2019-05-21 00:35:25

标签: python

这是在Python 2.7中。 string.maketrans函数应该返回一个翻译映射,该映射是一个完全由256个字符组成的字符串。

为什么使用print命令看不到该字符串?

allchars = string.maketrans('','')
print 'all chars are = ', allchars

此输出为空白。

我可以使用:

print repr(allchars)

这将返回表格,但是我想知道为什么print不显示任何内容

1 个答案:

答案 0 :(得分:1)

请注意,转换表中的大多数字符都不可打印。您可以将它们发送到终端,但是它们并不能完全满足您的期望。

这是我使用Python 2.7.15rc1的结果:

$ yarn
yarn install v1.15.2
[1/4]   Resolving packages...
[2/4]   Fetching packages...
[3/4]   Linking dependencies...
[4/4]   Building fresh packages...
[1/2] ⢀ fsevents
warning Error running install script for optional dependency: "/my_project_folder/node_modules/fsevents: Command failed.
Exit code: 1
Command: node install
Arguments:
Directory: /my_project_folder/node_modules/fsevents
Output:
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@0.10.3
node-pre-gyp info using node@12.1.0 | darwin | x64
node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp info check checked for \"/my_project_folder/node_modules/fsevents/lib/binding/Release/node-v72-darwin-x64/fse.node\" (not found)
node-pre-gyp http GET https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.2.7/fse-v1.2.7-node-v72-darwin-x64.tar.gz
node-pre-gyp http 404 https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.2.7/fse-v1.2.7-node-v72-darwin-x64.tar.gz
node-pre-gyp WARN Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.2.7/fse-v1.2.7-node-v72-darwin-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not found for fsevents@1.2.7 and node@12.1.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp)
node-pre-gyp http 404 status code downloading tarball https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.2.7/fse-v1.2.7-node-v72-darwin-x64.tar.gz
node-pre-gyp WARN Pre-built binaries not installable for fsevents@1.2.7 and         node@12.1.0 (node-v72 ABI, unknown) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error Connection closed while downloading tarball file

换句话说,是ASCII表,后面是一堆废话(试图解码127以上的字节)。

相关问题