Skip to main content

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)

Release files for inab 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for inab 0.0.1
File Size Uploaded
inab-0.0.1.tar.gz 1.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for inab 0.0.1
File Interpreter ABI Platform
inab-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 3.2 kB

Release files / inab-0.0.1.tar.gz

Download URL inab-0.0.1.tar.gz
Size 1.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2a4fab334622b3143b2775d17eef54c578cfabc13cf11af22f98a527f39056cf
BLAKE2b-256 checksum
How to use checksums
324d2f7a8e6fcaab715114f989bf535b6c93013e1cf91db1c5e8a6918a4b123b
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / inab-0.0.1-py3-none-any.whl

Download URL inab-0.0.1-py3-none-any.whl
Size 1.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
495c3b944b6e46cf740c1fff3c5beb093acc47388d834e82d5764fc2c57046a5
BLAKE2b-256 checksum
How to use checksums
1563c4354ffdcae3f57a179f1a39a08dad6f118241ffebf968b9d976059313e7
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page