Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Python argv and special characters

6 views
Skip to first unread message

trape...@gmail.com

unread,
Sep 23, 2005, 3:49:27 AM9/23/05
to
Hi.

Platform: Win XP
Python version: 2.4.1
Running script from: cmd.exe (windows console)

I am having some trouble passing arguments to a python script having
special characters. In my case the argument is a filename (eg.
udtræk.xml). It seems like python tries to guess the encoding in which
the arguments are passed, instead of just recieving them in unicode,
thus using main() instead of wmain() inside the interpreter. So I get
an exception "IOError: [Errno 2] No such file or directory:
'udtr\xe6k.xml'" as a result.

How can I ensure a safe passing of arguments maybe having speciel
characters within.

Best Regards
Jakob Simon-Gaarde

Neil Hodgson

unread,
Sep 23, 2005, 4:03:37 AM9/23/05
to
Jakob Simon-Gaarde:

> How can I ensure a safe passing of arguments maybe having speciel
> characters within.

Use ctypes to call the Windows GetCommandLine function. The
CommandLineToArgvW function can be used to break up the command line
string into arguments.

Neil

trape...@gmail.com

unread,
Sep 23, 2005, 4:52:50 AM9/23/05
to
thanks :-) It seems a little overkill though, is it really the
only/best way?

Neil Hodgson

unread,
Sep 23, 2005, 5:34:02 AM9/23/05
to
Jakob Simon-Gaarde:

> thanks :-) It seems a little overkill though, is it really the
> only/best way?

Yes. I should have mentioned you want the wide version of the
function GetCommandLineW. I wrote a patch to allow unicode in argv but
later agreed that the patch should be rejected:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1231336&group_id=5470

Neil

0 new messages