This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.startfile() doesn\'t accept Unicode filenames
Type: Stage:
Components: Extension Modules Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, georg.brandl, huening, lemburg, rhettinger
Priority: normal Keywords:

Created on 2004-08-11 06:47 by huening, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
posix-startfile.diff georg.brandl, 2005-06-26 21:24
Messages (5)
msg22043 - (view) Author: Matthias Huening (huening) Date: 2004-08-11 06:47
WinXP, Python 2.3.4

os.startfile() seems to have problems with Unicode
filenames. Example:

>>> import tkFileDialog
>>> import os
>>> f = tkFileDialog.askopenfilename()
>>> type(f)
<type 'unicode'>
>>> os.startfile(f)

Traceback (most recent call last):
  File "<pyshell#10>", line 1, in -toplevel-
    os.startfile(f)
UnicodeEncodeError: 'ascii' codec can't encode
characters in position 14-16: ordinal not in range(128)
>>> 

msg22044 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-06-26 21:24
Logged In: YES 
user_id=1188172

Attaching a patch which should fix that.
msg22045 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2005-08-24 05:18
Logged In: YES 
user_id=80475

I'm unicode illiterate.  Passing to MAL for review.
msg22046 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2005-09-01 08:27
Logged In: YES 
user_id=38388

The path looks OK, but I can't test it on Windows
(os.startfile() is only available on Windows).

A note on style: you should always try to keep lines shorter
than 80 characters, e.g.:

--- CVS-Python/Modules/posixmodule.c    2005-08-15
10:15:27.000000000 +0200
+++ Dev-Python/Modules/posixmodule.c    2005-09-01
10:23:06.555633134 +0200
@@ -7248,7 +7248,8 @@
 {
        char *filepath;
        HINSTANCE rc;
-       if (!PyArg_ParseTuple(args, "s:startfile", &filepath))
+       if (!PyArg_ParseTuple(args, "et:startfile",
+                             Py_FileSystemDefaultEncoding,
&filepath))
                return NULL;
        Py_BEGIN_ALLOW_THREADS
        rc = ShellExecute((HWND)0, NULL, filepath, NULL,
NULL, SW_SHOWNORMAL);

msg22047 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-09-14 20:52
Logged In: YES 
user_id=1188172

Checked this in now. posixmodule.c r2.340, r2.329.2.4.
History
Date User Action Args
2022-04-11 14:56:06adminsetgithub: 40740
2004-08-11 06:47:56hueningcreate