python copy\u tree运行,但实际上并不将目录复制到目标

2024-06-16 09:26:26 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我只是想把一个目录复制到同一台windows机器上的另一个目录。这段代码运行没有任何错误,但我到了目录,它从来没有复制它。这是我的密码。有什么想法吗?你知道吗

import File
from distutils.dir_util import copy_tree


if __name__ == "__main__":

    sourceFolder = File.File
    targetFolder = File.File

    sourceFolder.filePath = 'C:\\Workspace\\PythonAutomation\\1-DEV\\PythonAutomation'
    targetFolder.filePath = 'C:\\Workspace\\PythonAutomation\\2-QA'


    copy_tree(sourceFolder.filePath, targetFolder.filePath)

编辑: 注意,dir中的内容是python脚本和visualstudio解决方案。这就是问题所在吗?复制树只能复制某些文件类型吗?你知道吗


Tags: import目录机器treewindows错误dirworkspace
1条回答
网友
1楼 · 发布于 2024-06-16 09:26:26

基本上是这样的。因为你给了一个单一的,可变的对象(我猜这是一个类定义,但它不一定是)多个名字,通过一个名字改变它通过所有名字改变它。你知道吗

class File:
    class File:
        pass

spam = File.File
eggs = File.File

# spam and eggs refer to the *exact same thing*
assert spam is eggs

# we can lazily create a "cheese" attribute inside it
spam.cheese = 'leicester'
# but because spam and eggs are identical, this overwrites it
eggs.cheese = 'stilton'

assert spam.cheese == eggs.cheese
assert spam.cheese is eggs.cheese

这在功能上与简单情况相同:

spam = {'a': 1}
eggs = spam
eggs['a'] = 2
assert spam['a'] != 2 # fails

相关问题 更多 >