decode command line parameters - recomendend way

"Martin v. Löwis" martin at
Thu Apr 30 18:27:14 CEST 2009

> I want add full Unicode support in my scripts. Now I have encoutered theoretical
> problem with command line parameters. I can't find anything in that mater. But
> I develop solution which seems to work. Question is: Is it recommendend way to
> decode command line parameters:
> lFileConfig = None
> if len(sys.argv) > 1:
>    lFileConfig = unicode(sys.argv[1], locale.getpreferredencoding())
> Or maybe there is other solution?

That is the right way. Expect that decoding may fail, though - see PEP
383 how this issue will be solved in Python 3.1.


More information about the Python-list mailing list