【问题标题】:perl Encode::_utf8_off in pythonperl Encode::_utf8_off 在 python 中
【发布时间】:2015-09-06 01:46:11
【问题描述】:

Perl 的 Encode::_utf8_off 的 Python 等效函数是什么?

【问题讨论】:

  • 不要用另一种语言给出函数的名称,说出你想做什么。

标签: python perl


【解决方案1】:

你应该永远不要使用Encode::_utf8_off

您可能正在尝试使用 UTF-8 对字符串进行编码。在 Perl 中,您可以使用以下任何一种:

  • utf8::encode($s);
  • utf8::encode( my $utf8 = $uni );
  • use Encode qw( encode_utf8 ); my $utf8 = encode_utf8($uni);
  • use Encode qw( encode ); my $utf8 = encode('UTF-8', $uni);

我不知道 Python,但快速搜索发现

utf8 = uni.encode('UTF-8', 'strict')

【讨论】:

  • 我的问题类似于:stackoverflow.com/questions/12994100/… Encode::_utf8_off 解决了我的问题。但是我的脚本的一部分是在 python 中,而 python 脚本也有同样的问题。所以我在 python 中寻找相同的函数,以便我可以在那里应用。
  • 我再说一遍:永远不要使用Encode::_utf8_off。梦露传递了一些没有编码到decode 的东西。解决孟璐问题的方法不是加_utf8_off。解决方案是修复他们的错误代码。
  • 嘿.. 谢谢我会尝试 utf::downgrade。但只是想知道,你能解释一下为什么我不应该使用 Encode::_utf8_off 吗?
  • 因为有时它会utf8::encode,有时它什么都不做。
猜你喜欢
  • 2011-06-28
  • 2020-08-21
  • 2012-08-27
  • 2016-03-13
  • 1970-01-01
  • 2015-08-02
  • 2017-07-21
  • 2019-04-08
  • 2019-01-05
相关资源
最近更新 更多