Index: Lib/tokenize.py =================================================================== --- Lib/tokenize.py (révision 70478) +++ Lib/tokenize.py (copie de travail) @@ -480,3 +480,13 @@ # library that expect to be able to use tokenize with strings def generate_tokens(readline): return _tokenize(readline, None) + +def open_script(filename, mode='r'): + """ + Open a Python source code file with the correct encoding. + Use detect_encoding() to read the cookie. + """ + with open(filename, 'rb') as fp: + encoding, lines = detect_encoding(fp.readline) + return open(filename, mode, encoding=encoding) +