Weird UTF-8 one-liner interpreter bug
<p>So, I have this unholy abomination of a program:</p>

<pre><code>print((lambda raw, name_file: ((lambda start_time, total, lines, names: ((lambda parsed: ('\n'.join(str(10*(parsed[0][name]+parsed[1][name]/2)/total).ljust(6) + name for name in names)))(list(map(lambda x: __import__("collections").Counter(x), map(lambda x: list(map(lambda x: x[1], x)), [list(group[1]) for group in __import__("itertools").groupby(sorted([list(group[1])[0] for group in __import__("itertools").groupby(sorted(list(map(lambda x: [x[3], ' '.join([x[4], x[5], x[6]]), __import__("datetime").datetime.strptime(x[0] + ' ' + x[1], '%Y.%m.%d %H:%M:%S')], map(str.split, filter(lambda x: (any(name.strip() in x for name in names) and "OK ( 0 )" in x), lines))))), lambda x: (x[0], x[1]))], key = lambda x: (x[2], x[1], x[0])), lambda x: ((x[2] &lt; start_time+__import__("datetime").timedelta(days=7)) + (x[2] &lt; start_time+__import__("datetime").timedelta(days=14))))]))))))(__import__("datetime").datetime.strptime(raw.readline().strip(), '%d.%m.%Y %H:%M'), int(raw.readline()), map(lambda x: x.replace("ÐÐ¸Ð½ÑÐµÐ½", ""), raw.readlines()), list(map(str.strip, name_file.readlines())))))(raw = open("test.txt", "r"), name_file = open("names.txt", "r")))
</code></pre>

<p>(probably better on <a href="http://pastebin.com/XFTK63EN" rel="nofollow">pastebin</a>)</p>

<p>It <em>almost</em> works, but the way it does <em>not</em> work is very weird and looks like an interpreter bug to me.</p>

<p>Now, the only non-ASCII characters in the code are in the string "ÐÐ¸Ð½ÑÐµÐ½" in the end, and even then they are perfectly UTF-8-compatible, which is supposed to be the default encoding. Now, the problem is, Python throws this error:</p>

<pre><code>Non-UTF-8 code starting with '\xd1' in file lulz.py on line 1, but no encoding declared;
</code></pre>

<p>And it's not just some weird encoding problem! If I remove the last "Ð½" in the string, the program runs just fine; the moment I add <strong>any</strong> russian letter in it's place, the interpreter crashes. Even if I only add one linebreak before this place, anywhere, just so that this string is on the second line of the source code, the interpreter does not crash.</p>

<p>Of course, I can't provide a <em>Minimal</em> example, given how finicky and unstable this is, but I'm pretty sure this is not the expected behaviour. Is this a bug in the interpreter or am I doing something wrong?</p>

<p>BTW, it may require "names.txt" and "test.txt" to be present; if you want to test, you can create two empty files with these names.</p>

<p><strong>UPD</strong> Even adding a space <em>after any single <code>(</code></em> makes everything work! Something is definitely wrong here.</p>

<p><strong>UPD2</strong> I am using Python 3.5.1</p>

<p><code>&gt;&gt;&gt; python3 --version
Python 3.5.1</code></p>

<p><strong>UPD3</strong> here is my <a href="http://dropmefiles.com/zhkT9" rel="nofollow">file.</a></p>

<p><strong>UPD4</strong> and here is a hexdump: <a href="http://pastebin.com/5R1rbtc3" rel="nofollow">http://pastebin.com/5R1rbtc3</a></p>

<p><strong>UPD5</strong> apparently, this problem can only be reproduced on a Mac. I feel like different behaviour on different platforms is not intended.</p>

<p>The bug is in your expectation of what the default source file encoding is.
It is only UTF-8 when you're using Python 3.x (I checked, 3.5 parses the abomination without problems)</p>

<p>Python 2.x defaults to ASCII so add an encoding comment as first line in this abomination and you're good to go</p>

<pre><code># -*- coding: utf8 -*-
</code></pre>

python python-3.x utf-8 character-encoding