Dear all,
I have a small script wich is supposed to process two images passed as arguments in commandline, but I don't know how to handle these arguments when they are with non latin characters.
Here is an example of command

python.exe myscrit.py --first=xvalue "image1.png" "οισξφσιο.png"

If I isolate the arguments as follows

import sys, getopt
opts, args = getopt.getopt(sys.argv[1:], '', ['first='])    opts = dict(opts)
fval_name = opts.get('--first', 'xvalue')

and I print the second args I end up with a string like this ??s?fs??.png.
What am I doing wrong and how can I fix it?

I also tried the following in my script but nothing seems to work

# -*- coding: UTF-8 -*-
from __future__ import unicode_literals

import sys, traceback

Any help is appreciated.

10 Months
Discussion Span
Last Post by Gribouillis

This is a windows issue, so I cannot help you much, furthermore, it seems to be a python 2 issue only. You could try solutions such as <this one> for example.

The best thing to do is probably to move to python 3. Try with your install of python 3 if the same problem occurs. Also the getopt module is a tedious way to handle command line arguments, choose argparse instead (my favorite module for this is argh, see it in pypi).

Edited by Gribouillis


@Dave_15 I don't quite agree with you. First your post contains no obvious solution for this specific issue. Second I don't have a political agenda telling me to get more people to use python 3. Concerning unicode characters, many python 2 issues simply vanish by using python 3 because unicode is correctly handled in the language's very design. So why waste time solving issues that exist only because one uses an obsolete version of python ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.