JuanPablo JuanPablo - 2 years ago 210
Python Question

How to use nameFilters with QDirIterator?

In PySide, when I use

, how I can filter on files by name?

In the documentation, it talks about the parameter

But when I try it, it doesn't filter the files by extension:

from PySide import QtCore

it = QtCore.QDirIterator('.', nameFilters=['*.py'])
while it.hasNext():
print it.next()

>> ./.
>> ./..
>> my_script.py
>> another_file.txt

With this code, I expected to get only the files with the extension

Answer Source

The nameFilters parameter is not a keyword argument.

Unfortunately, PySide never raises an error if you pass keyword arguments that don't exist, which is a very poor design. APIs should never fail silently when given invalid inputs.

Anyway, your code will work correctly if you use a positional argument:

it = QtCore.QDirIterator('.', ['*.py'])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download