Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85f9814

Browse files
committed
Print encoded versions of the file names in test application. Fixes #496084
1 parent 7790297 commit 85f9814

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

Lib/lib-tk/tkFileDialog.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,20 @@ def askdirectory (**options):
124124
# test stuff
125125

126126
if __name__ == "__main__":
127+
# Since the file name may contain non-ASCII characters, we need
128+
# to find an encoding that likely supports the file name, and
129+
# displays correctly on the terminal.
130+
131+
# Start off with UTF-8
132+
enc = "utf-8"
133+
134+
# See whether CODESET is defined
135+
try:
136+
import locale
137+
enc = locale.nl_langinfo(locale.CODESET)
138+
except (ImportError, AttributeError):
139+
pass
140+
141+
print "open", askopenfilename(filetypes=[("all filez", "*")]).encode(enc)
142+
print "saveas", asksaveasfilename().encode(enc)
127143

128-
print "open", askopenfilename(filetypes=[("all filez", "*")])
129-
print "saveas", asksaveasfilename()

0 commit comments

Comments
 (0)