bookmark_borderPython error: SyntaxError: Non-ASCII character

I’m a heavy Python user. Python is the perfect language for me for a fast and easy way to script some useful and helpful tools. Something which I came across a longer time ago: Python has some problems with umlauts and other special characters. Even though the special character support has become way much better in Python 3, Python 2 still have problems here and expects some tweaks within your scripts. This article is going to show you how to exactly tweak your Python 2 scripts to get them working with umlauts and special characters.

What is it all about?

In Python 3 you can use special characters such as the German umlauts all the time. You will not run into any issue. But if you have to use Python 2, you will run into serious problems. For example, the following code will run with Python 3 but will produce errors with Python 2:

# This are german umlauts äöü

While we will get the expected result with Python 3, Python 2 will gives you the following error:

SyntaxError: Non-ASCII character '\xc3' in file on line 1, but no encoding declared; see for details

This error indicates, that Python 2 was unable to encode the umlauts which are written down in the script file. But there is a solution available …

The Solution

The solution is rather simple. Just put this into the first line of your Python script file and you will be read to go again:

# -*- coding: utf-8 -*-

For the example above the code will now look like this:

# -*- coding: utf-8 -*-
# This are german umlauts äöü

Save and rerun your script. Python 2 will now be able to work with it as well. The line which you have added is telling the Python 2 interpreter that the code contains characters, which are utf-8 based. Besides the german umlauts, there are a lot more special characters like in the spanish or french language which needs this line in order to get accepted by Python 2.
You want to learn more about Python? Then I recommend you the Python Crash Course book by Eric Matthes. This book gives you a lot of code examples, guides and tips about how to script in Python 2 and 3.

Further links

bookmark_borderRead user input in Java

Actually I’m playing around with Java after more than 3 years of development with C#. The reason is the easy and flexibel crossover platform development possibility.
I like C# as a language, but I dislike the .NET Framework. For me as a Linux user, .NET is useless. Sure, there is Mono, but in my opinion, Mono have to prove oneself before I would go with this solution.
Because of this reason, I searched at the Internet for some other languages, which I can choose as an alterantive and the most people said that there is Java at the nearst alternative to C#.
I’ve made some „Hello World“ tests and than I came to the point, which I wanted to read out some user console input. With C# you easily go with „Console.ReadLine“, but with Java, you have to do some more. For everbody who has the same problem as me (to find a short an easy example to do that) here is a short code snippet of what I have done:

BufferedReader bin = new BufferedReader(new InputStreamReader(;
String foo = bin.readLine();
System.out.println(„You said: “ + foo);

As you can see, there is also an „readLine“ function available under Java, but you have to create an object with an InputStreamReader so that you can use it.
Now, when you try to compile the whole thing, you will get an error message, that the IOException is not handeled. This is necessary and so we have to add this to the main function:

throws IOException

The Complete main function will look like this now:

public static void main(String[] args) throws IOException

At least don’t forget to import the needed libs:


Now, you should be able to enter something and get an output of your entered sentence / word.