convert escaped unicode sequence to human readable format

smatthewenglish

I've been using this python code:

pattern = u'丨フ丨ノ一丨ノ丶フノ一ノ丨フ一一ノフフ丶'
result = [u'<span id="z_i_t2_bis" title="\u7ad6\u6298\u7ad6\u6487\u6a2a\u7ad6\u6487\u637a\u6298\u6487\u6a2a\u6487\u7ad6\u6298\u6a2a\u6a2a\u6487\u6298\u6298\u637a">\u4e28\u30d5\u4e28\u30ce\u4e00\u4e28\u30ce\u4e36\u30d5\u30ce\u4e00\u30ce\u4e28\u30d5\u4e00\u4e00\u30ce\u30d5\u30d5\u4e36</span>']

if pattern in result[0]:
    print('found')

But this is cumbersome and moreover doesn't really do what I want, which is to get the escaped gobbledygook back into something comprehensible, as in that pattern. Is there some simple unix tool or commnand to perform this task quickly and efficiently?

seems that is one would work, but I tried it and it did not. i.e.,

result = "\u4e28\u30d5\u4e28\u30ce\u4e00\u4e28\u30ce\u4e36\u30d5\u30ce\u4e00\u30ce\u4e28\u30d5\u4e00\u4e00\u30ce\u30d5\u30d5\u4e36"

result.decode('utf-8')

which generated the error: attribute error 'str' object has no attribute 'decode'

Mark Ransom

If you simply print(result) then you'll get the "gobbledygook", because that's what Python uses when it gives you an unambiguous output as an element of a list or tuple. But if you print the string directly, print(result[0]), it will try to print the natural characters as they were intended.

If you want to convert the characters to utf-8 yourself, use encode rather than decode. encode converts a Unicode string to bytes, decode produces a Unicode string from bytes.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Convert date from human readable format golang

分類Dev

What is this date time format? How to convert it into a human readable output? Why it returns this output?

分類Dev

Javascript: Convert timestamp to human readable date?

分類Dev

Format JSON encoded string into more human readable in Silverstripe

分類Dev

Cannot convert 16 digit number to human readable date

分類Dev

Convert Bigint data to human readable date-time in Sql

分類Dev

How to convert time date from JSON to human readable?

分類Dev

How to convert string to dig readable format rails?

分類Dev

Convert sql to c#: Human readable string truncation based on string length

分類Dev

Sorting human readable file sizes

分類Dev

Timestamp to human readable date with angular

分類Dev

How to convert hadoop sequence file to json format?

分類Dev

Human readable dmesg time stamps on OpenWRT

分類Dev

Ping output - epoch time to human readable

分類Dev

Why is `--human-readable` needed and not default?

分類Dev

How do I convert API supplied date/time string into readable format?

分類Dev

How to convert dataframe into usable format for sequence mining in R?

分類Dev

Fix a unicode string broken by (some) escaped backslashes

分類Dev

Show human-readable file sizes in OSX terminal

分類Dev

Dart - Converting Milliseconds Since Epoch (UNIX timestamp) into human readable time

分類Dev

Mapping Android device models to human-readable brand names

分類Dev

How to force 'top' to show human readable values for %MEM RES and VIRT

分類Dev

Human readable URL Scheme for ASP.NET MVC

分類Dev

Show human-readable file sizes in the default PowerShell ls command

分類Dev

Create unique, human-readable identifiers (hash?) for strings in R

分類Dev

How to change mounted HDD UUID to human-readable?

分類Dev

Convert UNIX to readable date in javascript

分類Dev

Convert unicode à °¨à ±‡à °¨à ± à into normal unicode message

分類Dev

Bash prompt does not convert escaped characters

Related 関連記事

  1. 1

    Convert date from human readable format golang

  2. 2

    What is this date time format? How to convert it into a human readable output? Why it returns this output?

  3. 3

    Javascript: Convert timestamp to human readable date?

  4. 4

    Format JSON encoded string into more human readable in Silverstripe

  5. 5

    Cannot convert 16 digit number to human readable date

  6. 6

    Convert Bigint data to human readable date-time in Sql

  7. 7

    How to convert time date from JSON to human readable?

  8. 8

    How to convert string to dig readable format rails?

  9. 9

    Convert sql to c#: Human readable string truncation based on string length

  10. 10

    Sorting human readable file sizes

  11. 11

    Timestamp to human readable date with angular

  12. 12

    How to convert hadoop sequence file to json format?

  13. 13

    Human readable dmesg time stamps on OpenWRT

  14. 14

    Ping output - epoch time to human readable

  15. 15

    Why is `--human-readable` needed and not default?

  16. 16

    How do I convert API supplied date/time string into readable format?

  17. 17

    How to convert dataframe into usable format for sequence mining in R?

  18. 18

    Fix a unicode string broken by (some) escaped backslashes

  19. 19

    Show human-readable file sizes in OSX terminal

  20. 20

    Dart - Converting Milliseconds Since Epoch (UNIX timestamp) into human readable time

  21. 21

    Mapping Android device models to human-readable brand names

  22. 22

    How to force 'top' to show human readable values for %MEM RES and VIRT

  23. 23

    Human readable URL Scheme for ASP.NET MVC

  24. 24

    Show human-readable file sizes in the default PowerShell ls command

  25. 25

    Create unique, human-readable identifiers (hash?) for strings in R

  26. 26

    How to change mounted HDD UUID to human-readable?

  27. 27

    Convert UNIX to readable date in javascript

  28. 28

    Convert unicode à °¨à ±‡à °¨à ± à into normal unicode message

  29. 29

    Bash prompt does not convert escaped characters

ホットタグ

アーカイブ