I just started to learn coding in Python and I have a simple Python program that returns
is the name that a user can input into CMD as a parameter for this Python program. If no input is given it'll return
. It works fine, but when I for instance input the name
it strips the strike from the
and the program returns
instead of the correct
In Windows CMD I used the CD command to go to the folder containing the Python program and there I execute the Python program by using the statement:
My script looks like this (it is originally from Google's Python exercises (source
) and I edited it to make it work for unicode characters with Python version 2.7 and also replaced 'hello' with 'cześć' for instance):
# -*- coding: utf-8 -*-
# Define a main() function that prints a little greeting.
# Get the name from the command line, using 'World' as a fallback.
if len(sys.argv) >= 2:
name = sys.argv.decode('cp1252')
name = u'Świat'
str = u'Cześć '+name
# This is the standard boilerplate that calls the main() function.
if __name__ == '__main__':
Originally I decoded the
, but somehow when I used the letter
it would throw an ugly exception (see this SO answer
). Using either
results in the Polish letters (e.g. ĄĆĘŁŃŚŻŹ) getting stripped of their accents, with the exception of the letter
which seems to keep their accent when using
, because using that letter with
caused the previously mentioned exception.
So my question is, how do I retrieve the string intact with the accents from CMD to use in my Python program?
I won't accept answers that suggest to remove/ignore the accents!