title: Latex: listings does not replace special characters correctly
body: <p>I want to include python scripts in a document, but in those scripts I use characters like á é í ó ú. I am using the literate option of <code>\lstet</code>. Here is an example code:</p>
  <pre><code>\documentclass[12pt]{article}
  
  \usepackage[utf8]{inputenc}
  \usepackage[spanish,es-tabla]{babel}
  \usepackage{listings, pythonhighlight}
  \lstset{ 
      basicstyle=\ttfamily\small,
      breakatwhitespace=false,
      breaklines=true,        
      inputencoding=utf8,
      extendedchars=false, 
      literate= {á}{{\'a}}1 
      {é}{{\'e}}1 
      {í}{{\'i}}1 
      {ó}{{\'o}}1 
      {ú}{{\'u}}1
  }
  
  \begin{document}
      \lstinputlisting[language=Python]{example.py}
  \end{document}
  
  </code></pre>
  <p>With a python script (example.py) that contains:</p>
  <pre><code># coding = utf-8
  # á é í ó ú
  </code></pre>
  <p>I get a pdf like this:</p>
  <p><a href="https://i.stack.imgur.com/Lcfnc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lcfnc.png" alt="pdf I get" /></a></p>
  <p>where all special characters are substituted by the last one in the literate option.</p>
  <p>Why is this happening?</p>
  <p><strong>EDIT</strong></p>
  <p>Using the package <code>listingsutf8</code> instead of <code>listings</code> with</p>
  <pre><code>    basicstyle=\ttfamily\small,
      breakatwhitespace=false,
      breaklines=true,        
      inputencoding=utf8,
      extendedchars=false, 
      literate= {á}{{\'a}}1 
      {é}{{\'e}}1 
      {í}{{\'i}}1 
      {ó}{{\'o}}1 
      {ú}{{\'u}}1
  }
  </code></pre>
  <p>does NOT change anything.
  Using <code>listingsutf8</code> with:</p>
  <pre><code>\lstset{ ...
      inputencoding=utf8/latin1,
     ...
  }
  </code></pre>
  <p>allows for all the special characters I need but misplaces them (all of them appear at the beginning of the python comment and not in the place they should be in the sentence).</p>
  <p>Using <code>listingsutf8</code> with:</p>
  <pre><code>\lstset{ ...      
      inputencoding=latin1,
  ...
  }
  </code></pre>
  <p>does not work either because my code is utf8, so it gives me errors compiling.</p>