[英]Complement maketrans in python for translate
For translating tr
in perl to python, I am using string.maketrans
and str.translate
.为了将 perl 中的tr
翻译为 python,我使用的是string.maketrans
和str.translate
。 However, for the perl expression:但是,对于 perl 表达式:
$val =~ tr/\0-\377//c
The user is asking for the complement of the translation.用户要求翻译的补充。 How I generate python code for that?我如何为此生成 python 代码?
I assume you want to delete characters not int the range of ordinal values [0-255], then you could simply do我假设您想删除不在序数值 [0-255] 范围内的字符,那么您可以简单地执行
val = "".join([ch for ch in val if 0o000 <= ord(ch)<= 0o377])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.