2

I want to loop over all files in a directory. I tried glob:

from glob import glob
for filename in glob('*'):
    print filename

and I tried fnmatch:

import fnmatch
import os
for file in os.listdir('.'):
    if fnmatch.fnmatch(file, '*'):
        print(file)

If the filename contains a german character (ä,ö,ü,...) then the print function prints an empty line. How can I handle int'l characters in this case?

UPDATE
Works in GIMP 2.10.16 Python-Fu Console 2.7.17 on Debian, but not on a Windows system (same versions).

And I only get the blank line the 2nd time I paste and execute the script in the console. The first time after GIMP/Pythen-Fu start, a lot of error messages are displayed in the file list, instead of the correct filenames:

C:\Users\jamacoe\AppData\Local\Programs\GIMP 2\lib\gimp\2.0\plug-ins\python-console/pyconsole.py:74: GtkWarning: gtk_text_buffer_emit_insert: assertion 'g_utf8_validate (text, len, NULL)' failed self.buffer.insert_with_tags_by_name(pos, text, self.tag_name)
C:\Users\jamacoe\AppData\Local\Programs\GIMP 2\lib\gimp\2.0\plug-ins\python-console/pyconsole.py:74: GtkWarning: Invalid text buffer iterator: either the iterator is uninitialized, or the characters/pixbufs/widgets in the buffer have been modified since the iterator was created.
You must use marks, character numbers, or line numbers to preserve a position across buffer modifications.
You can apply tags and insert marks without invalidating your iterators, but any mutation that affects 'indexable' buffer contents (contents that can be referred to by character offset)
will invalidate all outstanding iterators
self.buffer.insert_with_tags_by_name(pos, text, self.tag_name)
C:\Users\jamacoe\AppData\Local\Programs\GIMP 2\lib\gimp\2.0\plug-ins\python-console/pyconsole.py:74: GtkWarning: gtk_text_buffer_apply_tag_by_name: assertion 'gtk_text_iter_get_buffer (end) == buffer' failed
self.buffer.insert_with_tags_by_name(pos, text, self.tag_name)

jamacoe
  • 519
  • 4
  • 16
  • Which version of Python? – Błotosmętek Feb 19 '20 at 19:25
  • @blotosmetek , I am on Python 2.7.16 in the Python console of the current GIMP version 2.10.12 – jamacoe Feb 19 '20 at 19:34
  • I checked on 2.7.16 (under Debian) and your first snippet worked correctly for me on a directory containing files `Düsseldorf`, `Münster`, `Köln`. So maybe the problem is GIMP rather than Python? – Błotosmętek Feb 19 '20 at 19:50
  • Could be locale (mine is `LANG=en_US.UTF-8`)? I've tried in python-fu (2.7.17) console of GIMP (2.10.14) abd I also got files names mit Umläute printed just fine. – Ondrej K. Feb 19 '20 at 20:25
  • I have tried that in Debian, same Phyton version, and it worked too. The OS, GIMP and Python is English. My german Windows 10 is in a VirtualBox on the same computer, now I installed GIMP in English on Windows and it still doesn't work there. But I need the program to run on Windows. Which locale would I need to set, Windows or Fu-Python? What is the easiest way to do that? – jamacoe Feb 19 '20 at 20:45

0 Answers0