Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
byte types
#1
i find many times i write some code or a function or a method that does something with strings and i want it to also handle byte strings since i use those a lot. so initially i coded a test like:
if isinstance(variable,(bytes,bytearray)):
    ...
which woks OK in Python3 but fails in Python2 because bytes is the same as str in Python2. so, i came up with this way to do the test so that it only tests for bytearray when in Python2 when bytes is the same as str:
if isinstance(variable,(bytes,bytearray)[bytes==str:]):
     ...
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
byte types - by Skaperen - Oct-31-2018, 10:44 PM
RE: byte types - by wavic - Nov-01-2018, 05:03 AM
RE: byte types - by Gribouillis - Nov-01-2018, 09:18 AM
RE: byte types - by Skaperen - Nov-01-2018, 06:22 PM
RE: byte types - by Gribouillis - Nov-01-2018, 08:08 PM
RE: byte types - by Skaperen - Nov-02-2018, 12:05 AM
RE: byte types - by Gribouillis - Nov-02-2018, 05:45 AM
RE: byte types - by Skaperen - Nov-02-2018, 02:48 PM
RE: byte types - by wavic - Nov-02-2018, 06:06 PM
RE: byte types - by Skaperen - Nov-04-2018, 09:32 PM
RE: byte types - by ichabod801 - Nov-05-2018, 02:24 AM
RE: byte types - by Skaperen - Nov-06-2018, 12:55 AM
RE: byte types - by wavic - Nov-05-2018, 07:58 AM
RE: byte types - by Gribouillis - Nov-06-2018, 08:01 AM
RE: byte types - by Skaperen - Nov-07-2018, 04:03 AM
RE: byte types - by Gribouillis - Nov-07-2018, 09:19 PM
RE: byte types - by Skaperen - Nov-07-2018, 09:26 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020