cannot open file with non-ASCII filename

Ulli Horlacher framstag at rus.uni-stuttgart.de
Mon Dec 14 11:24:54 EST 2015


With Python 2.7.11 on Windows 7 my users cannot open/read files with
non-ASCII filenames. They use the Windows explorer to drag&drop files into
a console window running the Python program.
os.path.exists() does not detect such a file and an open() fails, too.

My code:


  print("\nDrag&drop files or directories into this window.")
  system('explorer "%s"' % HOME)
  file = get_paste()
  if not(os.path.exists(file)): die('"%s" does not exist' % file)


def get_paste():
  import msvcrt
  while True:
    c = msvcrt.getch()
    if c == '\t': return ''
    if c == '\003' or c == '\004': return None
    if not (c == '\n' or c == '\r'): break
  paste = c
  while msvcrt.kbhit():
    c = msvcrt.getch()
    if c == '\n' or c == '\r': break
    paste += c
  if match(r'\s',paste): paste = subst('^"(.+)"$',r'\1',paste)
  return paste


-- 
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum IZUS/TIK         E-Mail: horlacher at tik.uni-stuttgart.de
Universitaet Stuttgart         Tel:    ++49-711-68565868
Allmandring 30a                Fax:    ++49-711-682357
70550 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/



More information about the Python-list mailing list