You can use Python's own tokenizer to check!
import tokenize
import io
line = b'0xbin()'
print(' '.join(token.string for token in tokenize.tokenize(io.BytesIO(line).readline) if token.type!=59))
This prints the tokens in your string, separated by spaces. In this case, the result will be:
0xb in ( )
In other words, it returns False because the number 11 (0xb
) is not in the empty tuple (()
).
(Thanks to Roman Odaisky for suggesting the use of tokenize
in the comments!)
EDIT: To explain the code a bit more thoroughly: the tokenize
function expects input in a bit of a weird format, so io.BytesIO(line).readline
is a function that turns a sequence of bytes into something tokenize
can read. tokenize
then tokenizes it and returns a series of namedtuple
s; we take the string representing each one and join them together with spaces. The type != 59
part is used to ignore the encoding specifier that would otherwise show up at the beginning.
0xbin(013,37)
– DemilitarizeTrue
you can try0xbin(11,)
with a single argument – Paleogeography0xbin(013,37)
will also give you True ;) (in Python 2.7) – Demilitarize0xb
andin
should be treated as an invalid token. – Grievous0xband()
. Tokenizer is greedy and takes 0xba as a token. – Fluent