title: Error "decoding str is not supported" Custom str Class Python
body: <p>I was building a class that would work like a switch;</p>
  <p>such custom class would have been a string, with an inner list, whereas the string identifies the current position of the switch (&quot;on&quot;) and the list covers all the possible positions ([&quot;on&quot;,&quot;off&quot;,&quot;halfway on&quot;, &quot;kinda dead but still on&quot;, ...];</p>
  <p>While initializing an instance of this class, I would accept an indefinite number of possible positions;</p>
  <p>Hence the code</p>
  <pre><code>class switch(str):
      pos=[]
      def __init__(self,*positions):
          self.pos=[str(el) for el in positions]
          self=self.pos[0]
      def swap(self):
          try:
              self=self.pos[self.pos.index(self)+1]
          except IndexError:
              self=self.pos[0]
  </code></pre>
  <p>and the call</p>
  <p><code>mood=switch(&quot;upbeat&quot;,&quot;depressed&quot;,&quot;horny&quot;)</code></p>
  <p>That quite doesn't work. The error goes like this:</p>
  <p><code>TypeError: decoding str is not supported</code></p>
  <p>Of course there are better ways to make this Switch class (this was just a draft of a quick insertion) and eventually, I already did; still I didn't understand the origins of that error - whose search through Google wasn't useful - and angered enough about it that I finally decided to sign up here on Stack and post about it.
  What do you guys think about it?</p>
  <p>Googling it up, it seems like the error would turn off when trying to concatenate strings like <code>&quot;str1&quot;,&quot;str2&quot;</code> and not like <code>&quot;str1&quot;+&quot;str2&quot;</code>; then I think it's safe to keep suspicions around the <code>*positions</code> thing, with it not unpacking the strings as separate variables, but trying to guess I wanted them to be joined as one but failed at it as I wasn't using the + concatenator.</p>
  <p>That's what came to my mind.</p>
  <p>Otherwise, if I'm wrong, I've seen the error pop up only while playing with formats and stuff. Which is pretty way off in this case.</p>