Отправка списка шаблонов в ignore_patterns copytree дает TypeError: unhashable тип: 'list'

Я работаю над сценарием Python, который выдает TypeError: unhashable type: 'list', когда я пытаюсь использовать список расширений в качестве ignore_patterns copytree. Я не уверен, 1. Почему это не сработает, и 2. Как это исправить.

# allFileTypes is the list of all extensions in source_dir
# grabbed with function getFileExtList
allFileTypes = getFileExtList(source_dir)
# delete the blank file type
del allFileTypes[0]

#  Open a window to choose the files to copy
copyList = eg.multchoicebox(msg='Select the file types to copy',
                choices=(allFileTypes))

# List comprehension to make an ignore list for copytree
ignoreList = [x for x in allFileTypes if x not in copyList]


# Open a window to choose the destination directory
root_dir = eg.diropenbox(title='Choose Destination Directory')

# Take the basename of source_dir adding it to root_dir or os.mkdir will
# will break on the existing directory
dest_dir = os.path.join(root_dir, os.path.basename(source_dir))

# copytree everything from the source_dir to the dest_dir ignoring
# all files types not chosen from the list
copytree(source_dir, dest_dir, ignore=ignore_patterns(ignoreList))

1 ответ

Решение
copytree(source_dir, dest_dir, ignore=ignore_patterns(*ignoreList))

ignore_patterns получает все шаблоны как позиционные аргументы, а не как список.

Другие вопросы по тегам