kyrenia
kyrenia

Reputation: 5575

Detect byte objects in python

How do i detect <class 'bytes'> objects in Python?

I want something along the lines of

 if type(x) == bytes:
     doesomething(x)

Upvotes: 0

Views: 1292

Answers (1)

Moses Koledoye
Moses Koledoye

Reputation: 78554

You can simply do:

if type(x) is bytes

Or:

if isinstance(s, bytes)

Upvotes: 2

Related Questions