title: Python open("x", "r") function, how do I know or control which encoding the file is supposed to have?
body: <p>If a python script uses the <code>open("filename", "r")</code> function to open, and subsequently read, the contents of a text file, how can I tell which encoding this file is supposed to have?</p>
  
  <p>Note that since I'm executing this script from my own program, if there is any way to control this through environment variables, then that is good enough for me.</p>
  
  <p>This is Python 2.7 by the way.</p>
  
  <p>The code in question comes from Mercurial, it can be given a list of files to, say, add to the repository, through a file on disk, instead of passing them on the command line.</p>
  
  <p>So basically, instead of this:</p>
  
  <pre><code>hg add A B C
  </code></pre>
  
  <p>I can write out A, B and C to a file, with newlines between each, and then execute the following:</p>
  
  <pre><code>hg add listfile:input.txt
  </code></pre>
  
  <p>The code that ends up reading this file is this:</p>
  
  <pre><code>files = open(name, 'r').read().split(delimiter)
  </code></pre>
  
  <p>Hence my question. The answer I was given on IRC when I asked which encoding I should use was this:</p>
  
  <blockquote>
    <p>it is the same encoding than the one you use on command line when passing a file argument</p>
  </blockquote>
  
  <p>I take this to mean that it is the same encoding I "use" when I execute Mercurial (hg). Since I have no idea which encoding that is, I just give everything to the .NET Process object, I ask here.</p>