您好我试图简单地将目录复制到同一台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)
修改 请注意,目录中的内容是python脚本和Visual Studio解决方案。这可能是问题吗?是否只有copy_tree可以复制的某些文件类型?
答案 0 :(得分:1)
这基本上是发生了什么。因为你给了一个可变的对象(我猜它是一个类定义,但它不一定是)多个名称,通过一个名称改变它会通过所有名称改变它。
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