A library for decoding a byte marked as a string
Project description
When reading a file containing bytes using Python, you are often looking to read it like this b"\xd8\xa7\xd9\x84\xd8\xa8\xd9\x84\xd9\x8a\xd8\xba, for example o = open("bytes.txt", "rb") y = x.read() In fact, the exit is like this b"\\xd8\\xa7\\xd9\\x84\\xd8\\xa8\\xd9\\x84\\xd9\\x8a\\xd8\\xba, and when you try to decode it, you will get this back \xd8\xa7\xd9\x84\xd8\xa8\xd9\x84\xd9\x8a\xd8\xba, but it is a literal type, and whenever you code it, it will give you two slashback, and when you decode it, it takes you back to \xd8\xa7\xd9\x84\xd8\xa8\xd9\x84\xd9\x8a\xd8\xba. This problem I encountered when I was scraping a website and recving the data in bytes in a string type that included HTML. and it will face you in the future or you may have encountered before, I recently built a library to solve this problem where it is enough to pass it a byte with two slashback and it will decode it to the original text.
decode arabic utf-8
from inab import arabic_de str_bytes = "\\xd8\\xa7\\xd9\\x84\\xd8\\xa8\\xd9\\x84\\xd9\\x8a\\xd8\\xba" x = bytes(str_bytes, "utf-8") print(x) text = arabic_de(x) print(text)
decode english utf-16
from inab import eng_de str_bytes = "\\xff\\xfei\\x00n\\x00a\\x00b\\x00 \\x00l\\x00i\\x00b\\x00" text = eng_de(str_bytes) print(text)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file inab-0.0.1.tar.gz.
File metadata
- Download URL: inab-0.0.1.tar.gz
- Upload date:
- Size: 1.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a4fab334622b3143b2775d17eef54c578cfabc13cf11af22f98a527f39056cf
|
|
| MD5 |
2e23ca18c5a2555441112bde3e174b55
|
|
| BLAKE2b-256 |
324d2f7a8e6fcaab715114f989bf535b6c93013e1cf91db1c5e8a6918a4b123b
|
File details
Details for the file inab-0.0.1-py3-none-any.whl.
File metadata
- Download URL: inab-0.0.1-py3-none-any.whl
- Upload date:
- Size: 1.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
495c3b944b6e46cf740c1fff3c5beb093acc47388d834e82d5764fc2c57046a5
|
|
| MD5 |
450c67b8a52297965c465542a2770c0c
|
|
| BLAKE2b-256 |
1563c4354ffdcae3f57a179f1a39a08dad6f118241ffebf968b9d976059313e7
|