title: Removing non-ascii characters from any given stringtype in Python
body: <pre><code>&gt;&gt;&gt; teststring = 'aõ'
  &gt;&gt;&gt; type(teststring)
  &lt;type 'str'&gt;
  &gt;&gt;&gt; teststring
  'a\xf5'
  &gt;&gt;&gt; print teststring
  aõ
  &gt;&gt;&gt; teststring.decode("ascii", "ignore")
  u'a'
  &gt;&gt;&gt; teststring.decode("ascii", "ignore").encode("ascii")
  'a'
  </code></pre>
  
  <p>which is what i really wanted it to store internally as i remove non-ascii characters. Why did the decode("ascii give out a unicode string ?</p>
  
  <pre><code>&gt;&gt;&gt; teststringUni = u'aõ'
  &gt;&gt;&gt; type(teststringUni)
  &lt;type 'unicode'&gt;
  &gt;&gt;&gt; print teststringUni
  aõ
  &gt;&gt;&gt; teststringUni.decode("ascii" , "ignore")
  
  Traceback (most recent call last):
    File "&lt;pyshell#79&gt;", line 1, in &lt;module&gt;
      teststringUni.decode("ascii" , "ignore")
  UnicodeEncodeError: 'ascii' codec can't encode character u'\xf5' in position 1: ordinal not in range(128)
  &gt;&gt;&gt; teststringUni.decode("utf-8" , "ignore")
  
  Traceback (most recent call last):
    File "&lt;pyshell#81&gt;", line 1, in &lt;module&gt;
      teststringUni.decode("utf-8" , "ignore")
    File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
      return codecs.utf_8_decode(input, errors, True)
  UnicodeEncodeError: 'ascii' codec can't encode character u'\xf5' in position 1: ordinal not in range(128)
  &gt;&gt;&gt; teststringUni.encode("ascii" , "ignore")
  'a'
  </code></pre>
  
  <p>Which is again what i wanted.
  I don't understand this behavior. Can someone explain to me what is happening  here?</p>
  
  <p><strong>edit:</strong> i thought this would me understand things so i could solve my real program problem that i state here:
  <a href="https://stackoverflow.com/questions/3669436/converting-unicode-objects-with-non-ascii-symbols-in-them-into-strings-objects-in">Converting Unicode objects with non-ASCII symbols in them into strings objects (in Python)</a></p>