title: Turn functions to class methods in python
body: <p>To better structure the code I wanna create this subclass of string:
  class StringQuotes(str):
  pass:</p>
  <p>And put these functions and variables in there:</p>
  <pre><code>SINGLE_QUOTE = &quot;'&quot;
  
      
  def StringMask_QuoteSingle(s: str ) -&gt; str:
      return s.replace(SINGLE_QUOTE , SINGLE_QUOTE *2)
   
  
  def StringSingleQuote(s, quoteChar = SINGLE_QUOTE ):
      s = StringMask_QuoteSingle(s)
      return StringQuote( s, quoteChar)
  
  def StringQuote(s, quoteChar ):
      return quoteChar + s + quoteChar
  </code></pre>
  <p><code>SingleQuote</code> should be static constants. (For sake of simplicity it'll be also okay if it is not really readonly)</p>
  <p>When doing so (-&gt; see answer to my question) I encountered some problems / questions I thought it might be good to share that question here.
  I'll nice to have a review and to see ya ideas improvements.</p>
  <hr />
  <p>Well that's what I come up with:</p>
  <pre><code>class StringQuotes(str):
          
      SingleQuote = &quot;'&quot;
      
          
      def Mask_QuoteSingle( _ : str ) -&gt; str:
          return str.replace( _, &quot;'&quot; , &quot;'&quot; *2 )
                    
      
      def SingleQuote( _ , quoteChar = SingleQuote ):
          _  = _.Mask_QuoteSingle( )
          return StringQuotes.Quote( _ , quoteChar)
      
      def Quote( _ , quoteChar ):
          return quoteChar + _  + quoteChar
  </code></pre>
  <p>Instead of <code>self</code> I choose <code>_</code> since it looks nicer.
  However compared to a function all the need for this <code>self.</code> still clutters up view.</p>
  <p>Questions:</p>
  <ol>
  <li><p>Why can't I do <code>_.replace(...)</code> ? Why it has to be</p>
  <p>str.replace( _, ... )? Are there other ways?</p>
  </li>
  <li><p>... and about <code>str.replace( _, &quot;'&quot;)</code> how can I make it to use <code>SingleQuote</code>?</p>
  <ul>
  <li>just <code>replace( SingleQuote,</code> =&gt;complains it doesn't find
  SingleQuote</li>
  </ul>
  <blockquote>
  <p>=&gt;NameError: name 'DoubleQuote' is not defined</p>
  </blockquote>
  <ul>
  <li><code>replace( _.SingleQuote,</code> or <code>replace( StringQuotes.SingleQuote,</code></li>
  </ul>
  <blockquote>
  <p>=&gt;TypeError: must be str, not method
  What? Why SingleQuote is a method/function? I don't get it.
  It's a str or variable - but not function!  Is Python turning class variables into a 'property get()' (&lt;- I seen stuff like this in Visual Basic)</p>
  </blockquote>
  </li>
  <li><p>Why the use of <code>SingleQuote</code>  works in here:</p>
  <p>def SingleQuote( _ , quoteChar = SingleQuote ):</p>
  </li>
  <li><p>About <code>return StringQuotes.Quote(</code>
  Can I avoid duplication of <code>StringQuotes</code> and write something like <code>me.Quote(</code></p>
  </li>
  </ol>