Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7742

Python • Re: Import data and passing a variable into binary

$
0
0
I am unsure what you mean by "have it pass as binary."

The code line

Code:

server = b'secrets.myserver'
retrieves the string defined by myserver and then converts that to a binary string.

If that is your intent, then the answer to your question is yes.

Are you sure?

I'd expect that to return the literal bytes string (8 bit ASCII encoded) 'secrets.myserver'.

The b prefix to a string tells python to treat it as a byte string. It does not mean "binary".

To convert between byte and unicode string use bytes.decode() and str.encode() (or is it the other way around).

Statistics: Posted by thagrol — Sun Feb 09, 2025 10:51 pm



Viewing all articles
Browse latest Browse all 7742

Latest Images

Trending Articles



Latest Images