Skip to main content

Removes control characters / non-printing characters from strings and binaries

Project description

A function to remove control characters / non-printing characters from strings and binaries
$pip install get-the-hell-out-of-here

from get_the_hell_out_of_here import remove_escaped_characters

import numpy as np

test1 = np.array(["hi, my friend", "are you fine?"]).tobytes() #lets create some test data



#numpy as bytes

b"h\x00\x00\x00i\x00\x00\x00,\x00\x00\x00 \x00\x00\x00m\x00\x00\x00y\x00\x00\x00 \x00\x00\x00f\x00\x00\x00r\x00\x00\x00i\x00\x00\x00e\x00\x00\x00n\x00\x00\x00d\x00\x00\x00a\x00\x00\x00r\x00\x00\x00e\x00\x00\x00 \x00\x00\x00y\x00\x00\x00o\x00\x00\x00u\x00\x00\x00 \x00\x00\x00f\x00\x00\x00i\x00\x00\x00n\x00\x00\x00e\x00\x00\x00?\x00\x00\x00"

print(remove_escaped_characters(test1))

#Result:  b'hi, my friendare you fine?'



test2 = b"h\\x00\\x00\\x00i\\x00\\x00\\x00,\\x00\\x00\\x00 \\x00\\x00\\x00m\\x00\\x00\\x00y\\x00\\x00\\x00 \\x00\\x00\\x00f\\x00\\x00\\x00r\\x00\\x00\\x00i\\x00\\x00\\x00e\\x00\\x00\\x00n\\x00\\x00\\x00d\\x00\\x00\\x00a\\x00\\x00\\x00r\\x00\\x00\\x00e\\x00\\x00\\x00 \\x00\\x00\\x00y\\x00\\x00\\x00o\\x00\\x00\\x00u\\x00\\x00\\x00 \\x00\\x00\\x00f\\x00\\x00\\x00i\\x00\\x00\\x00n\\x00\\x00\\x00e\\x00\\x00\\x00?\\x00\\x00\\x00" #double escaped

print(remove_escaped_characters(test2))

# Result:   b'hi, my friendare you fine?'





test3 = "h\x00\x00\x00i\x00\x00\x00,\x00\x00\x00 \x00\x00\x00m\x00\x00\x00y\x00\x00\x00 \x00\x00\x00f\x00\x00\x00r\x00\x00\x00i\x00\x00\x00e\x00\x00\x00n\x00\x00\x00d\x00\x00\x00a\x00\x00\x00r\x00\x00\x00e\x00\x00\x00 \x00\x00\x00y\x00\x00\x00o\x00\x00\x00u\x00\x00\x00 \x00\x00\x00f\x00\x00\x00i\x00\x00\x00n\x00\x00\x00e\x00\x00\x00?\x00\x00\x00" #as string

print(remove_escaped_characters(test3))

#Result: hi, my friendare you fine?



test4 = "h\\x00\\x00\\x00i\\x00\\x00\\x00,\\x00\\x00\\x00 \\x00\\x00\\x00m\\x00\\x00\\x00y\\x00\\x00\\x00 \\x00\\x00\\x00f\\x00\\x00\\x00r\\x00\\x00\\x00i\\x00\\x00\\x00e\\x00\\x00\\x00n\\x00\\x00\\x00d\\x00\\x00\\x00a\\x00\\x00\\x00r\\x00\\x00\\x00e\\x00\\x00\\x00 \\x00\\x00\\x00y\\x00\\x00\\x00o\\x00\\x00\\x00u\\x00\\x00\\x00 \\x00\\x00\\x00f\\x00\\x00\\x00i\\x00\\x00\\x00n\\x00\\x00\\x00e\\x00\\x00\\x00?\\x00\\x00\\x00"  #as string - double escaped

print(remove_escaped_characters(test4))

#Result: hi, my friendare you fine?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

get_the_hell_out_of_here-0.12.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

get_the_hell_out_of_here-0.12-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file get_the_hell_out_of_here-0.12.tar.gz.

File metadata

File hashes

Hashes for get_the_hell_out_of_here-0.12.tar.gz
Algorithm Hash digest
SHA256 326c386e0833a4c4c82d2e30fb45ad3c74857a7621f54d6b3d2e3fe2483b5439
MD5 d5408d0bfd46873ff83d21ddbefa0937
BLAKE2b-256 c7402acce2407a03fe5c091f4709f557dd9d1511b5bcd850ceb2aceb2867d6a5

See more details on using hashes here.

File details

Details for the file get_the_hell_out_of_here-0.12-py3-none-any.whl.

File metadata

File hashes

Hashes for get_the_hell_out_of_here-0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 d21309c2d52cce7ae301b31341bc2341b65bf556e4ba4f42122f5122c9f0056e
MD5 8bc73b662eb4df0a1d49b774af1bede2
BLAKE2b-256 96c5fc64c8c7db0e9f6b01790da1c0b69a0b64b733c3b093d07408800bc45219

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page