简体   繁体   中英

How do I convert a regex with pack and hex from Perl to Python?

I am a newcomer to Python and am converting a Perl script. What is the Python equivalent to...

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

Any help is greatly appreciated.

您可能应该只使用urllib.unquote (python 2)/ urllib.parse.unquote (python 3),因为这似乎是您提供的代码试图完成的工作。

value = value.decode('hex')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM