Skip to content

Tag: byte

how to convert bytes to binary using python

so i want convert bytes to binary in python, but when i run it, there’s none in the result and i got error: ‘NoneType’ object is not iterable here’s the code i tried Answer Your function currently returns None because there’s no return statement. Perhaps instead of using print, y…

What are these symbols in ‘bytes’ type?

So, I have a single byte in bytes format looking something like that: It is quite easy to understand that a single byte is the two symbols(0-F) after ‘x’ But sometimes the pattern doesn’t match, containing more than two symbols after ‘x’. So, for example, if I use secrets.token_b…

Load a npz in numpy from bytes

I have a npz file saved from numpy that I can load by using numpy.load(mynpzfile). However, I would like to save this file as a part of a binary file, packed with another file. Something like: However, when reading back the npz I get an error. I have tried load and frombuffer, and both give me an error: fromb…

How to just change type of string to bytes? python

I am using Fernet and want to setup a basic authentication system, So on signup, I generate a key for fernet using key = Fernet.generate_key() Then I store that key in my cookies, so that it can be called during log in, but doing so converts the type of bytes to string. Suppose my key was – b’BNdX…

python size of byte string in bytes

I’m confused as to why: What exactly is b’123′? Answer As @jonrsharpe has stated, b’123′ is an immutable sequence of bytes, in this case of 3 bytes. Your confusion appears to be because len() and sys.getsizeof(b’123′) are not the same thing. len() queries for the numb…

converting large int list to byte string python

I need to convert int list into a byte string but I don’t know how. I can’t use bytes() because the values are too large. I get this error: The expected value is: Answer You can use .to_bytes to return an array of bytes representing an integer. Note: This works only in python 3.1 and above. For ex…