gpt4 book ai didi

python - 将模式列表发送到 copytree 的ignore_patterns 会出现 TypeError : unhashable type: 'list'

转载 作者:太空宇宙 更新时间:2023-11-03 18:51:21 25 4
gpt4 key购买 nike

我正在编写一个Python脚本,当我尝试使用扩展列表作为copytree的ignore_patterns时,该脚本会抛出TypeError: unhashable type: 'list'。我不确定,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))

最佳答案

copytree(source_dir, dest_dir, ignore=ignore_patterns(*ignoreList))

ignore_patterns 接收所有模式作为位置参数,而不是列表。

关于python - 将模式列表发送到 copytree 的ignore_patterns 会出现 TypeError : unhashable type: 'list' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18304881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com