[Python] Binary-Hex a NoneType Object ? [SOLVED] | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 11

[Python] Binary-Hex a NoneType Object ? [SOLVED]

I want to binary-hexlify the s value using the 'b' tag in the ( ) print(binascii.hexlify(b(s)) or what ? for more knowledge what I'! trying to do is doing it like this code : print(binascii.hexlify(b'hello worl'))

1st Jan 2018, 5:00 PM
warlord
warlord - avatar
6 Respostas
+ 10
SOLVED s = "hello" print(binascii.hexlify(bytes(s.encode('ascii'))))
24th Jan 2018, 9:24 PM
warlord
warlord - avatar
+ 13
@Krik Schafer I think your getting closer to the answer what I'm trying to do is is printing the NoneType with the 'b' tag now you're wondering which 'b' tag I With this one print(binascii.hexlify(b'hello') ^ did you get it I'm trying to use that tag with a NoneType
1st Jan 2018, 8:18 PM
warlord
warlord - avatar
+ 13
@Krik Schafer I know how to convert but I don't know how to do that with NoneType like should I use [] or {} to remind about the NoneType in the hexlify function attribute like in Ruby "#{reminding or some value}" can I do that ?
2nd Jan 2018, 5:45 PM
warlord
warlord - avatar
+ 8
By chance do you mean ASCII null? c=chr(0) print(c.encode()) Output: b'\x00' (Otherwise I'm trying to figure out what about the None value could help, e.g. from print(dir(None)) -- I don't see bytes conversion there and I'm not familiar with binascii(); I'll look though)
1st Jan 2018, 8:42 PM
Kirk Schafer
Kirk Schafer - avatar
+ 6
# Not sure on this, especially NoneType... but here are some things in the area I think you're asking. # This outputs a compatible type as binary 1/0's print("{:b}".format(97)) # b'...' is a bytes object and acts like a list (array) # Prints byte 0 (read the docs, below) print("{:b}".format(b'a'[0])) # ord() = ordinal character value (ASCII) print("{:b}".format(ord('a'))) # a = ASCII 97 # Hex print("{:#x}".format(97)) # strip 0x print("{:x}".format(97)) # Help for bytes objects. print(b''.__doc__) # Run this alone, it sometimes triggers timeout #print(help(b''))
1st Jan 2018, 7:02 PM
Kirk Schafer
Kirk Schafer - avatar
+ 5
Well, I wandered around some ideas but I'm not seeing anything direct, which means hackish solutions. None is a singleton constant representing the absence of value and special behavior: https://docs.python.org/3/library/constants.html#None These unsurprisingly return the same output: print(...hexlify(None.__repr__().encode())) print(...hexlify(b"None")) ...which leaves in my mind extending the NoneType class (or binascii's behavior) to return a None-position lookup table that's somehow added to encoded text, using a custom alphabet, or setting aside a hex value not already used within the current alphabet as a None placeholder.
1st Jan 2018, 9:50 PM
Kirk Schafer
Kirk Schafer - avatar