我正在尝试在Windows 7 64位上使用distutils.dir_util.据我可以从各种谷歌搜索收集,我可能需要单独安装一些distutils包?我确实有可用的基础distutils包,但是它似乎非常简单,并且缺少许多组件.试图研究distutils和windows总是让我看到python构建脚本以及如何将distutils打包为可再发行的python项目的一部分或构建我不感兴趣的EXE,我根本看不到任何关于从哪里获取这个的牵引力代码来自.
这已经很长时间了,但是我认为我从MSI安装程序安装了Python,不确定其他方法是否常见.这是我的翻译输出:
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import distutils
>>> distutils.dir_util
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'dir_util'
好的,看起来可以使用以下代码:
Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import distutils.core
>>> distutils.dir_util …目前,我正在处理一个同步两个文件夹的项目。我在以下示例中的文件夹将 ad Folder_1 命名为源,将Folder_2 命名为目标我想做以下事情。
我已经完成了第一点的一半,其中我能够将文件从 Folder_1 复制到 Folder_2。发送部分我可以将文件从 Folder_2 复制到 folder_1 的部分仍然存在。
以下是我的代码
import os, shutil
path = 'C:/Users/saqibshakeel035/Desktop/Folder_1/'
copyto = 'C:/Users/saqibshakeel035/Desktop/Folder_2/'
files =os.listdir(path)
files.sort()
for f in files:
        src = path+f
        dst = copyto+f
        try:
                if os.stat(src).st_mtime < os.stat(dst).st_mtime:
                        continue
        except OSError:
                        pass
                        shutil.copy(src,dst)#this is the case when our file in destination doesn't exist
                               =
print('Files copied from'+ path +'to' + copyto+ …我目前正在使用setuptools编写setup.py.我想将静态数据(不是Python模块)复制到site-packages.
问题是,当前文件夹层次结构的结构如下:
setup.py
src
    Pure Python Module
skeleton
    example
        __init__.py
    resources
        static
            error.css
            example.css
            logo_shadow.png
        template
            error.html
            example.html
    server.tmplt
我想将骨架目录复制到site-packages WHILE维护文件夹结构/层次结构,但我该怎么办呢?