python shutil模块函数“copyfile”和“copy”有什么区别? Python shutil.copy问题 为什么无法传值

python shutil\u6a21\u5757\u51fd\u6570copyfile\u548ccopy\u7684\u533a\u522b

shutil.copyfile( src, dst) \u4ece\u6e90src\u590d\u5236\u5230dst\u4e2d\u53bb\u3002\u5f53\u7136\u524d\u63d0\u662f\u76ee\u6807\u5730\u5740\u662f\u5177\u5907\u53ef\u5199\u6743\u9650\u3002\u629b\u51fa\u7684\u5f02\u5e38\u4fe1\u606f\u4e3aIOException. \u5982\u679c\u5f53\u524d\u7684dst\u5df2\u5b58\u5728\u7684\u8bdd\u5c31\u4f1a\u88ab\u8986\u76d6\u6389
shutil.move( src, dst) \u79fb\u52a8\u6587\u4ef6\u6216\u91cd\u547d\u540d
shutil.copymode( src, dst) \u53ea\u662f\u4f1a\u590d\u5236\u5176\u6743\u9650\u5176\u4ed6\u7684\u4e1c\u897f\u662f\u4e0d\u4f1a\u88ab\u590d\u5236\u7684
shutil.copystat( src, dst) \u590d\u5236\u6743\u9650\u3001\u6700\u540e\u8bbf\u95ee\u65f6\u95f4\u3001\u6700\u540e\u4fee\u6539\u65f6\u95f4
shutil.copy( src, dst) \u590d\u5236\u4e00\u4e2a\u6587\u4ef6\u5230\u4e00\u4e2a\u6587\u4ef6\u6216\u4e00\u4e2a\u76ee\u5f55
shutil.copy2( src, dst) \u5728copy\u4e0a\u7684\u57fa\u7840\u4e0a\u518d\u590d\u5236\u6587\u4ef6\u6700\u540e\u8bbf\u95ee\u65f6\u95f4\u4e0e\u4fee\u6539\u65f6\u95f4\u4e5f\u590d\u5236\u8fc7\u6765\u4e86\uff0c\u7c7b\u4f3c\u4e8ecp \u2013p\u7684\u4e1c\u897f
shutil.copy2( src, dst) \u5982\u679c\u4e24\u4e2a\u4f4d\u7f6e\u7684\u6587\u4ef6\u7cfb\u7edf\u662f\u4e00\u6837\u7684\u8bdd\u76f8\u5f53\u4e8e\u662frename\u64cd\u4f5c\uff0c\u53ea\u662f\u6539\u540d\uff1b\u5982\u679c\u662f\u4e0d\u5728\u76f8\u540c\u7684\u6587\u4ef6\u7cfb\u7edf\u7684\u8bdd\u5c31\u662f\u505amove\u64cd\u4f5c
shutil.copytree( olddir, newdir, True/Flase)
\u628aolddir\u62f7\u8d1d\u4e00\u4efdnewdir\uff0c\u5982\u679c\u7b2c3\u4e2a\u53c2\u6570\u662fTrue\uff0c\u5219\u590d\u5236\u76ee\u5f55\u65f6\u5c06\u4fdd\u6301\u6587\u4ef6\u5939\u4e0b\u7684\u7b26\u53f7\u8fde\u63a5\uff0c\u5982\u679c\u7b2c3\u4e2a\u53c2\u6570\u662fFalse\uff0c\u5219\u5c06\u5728\u590d\u5236\u7684\u76ee\u5f55\u4e0b\u751f\u6210\u7269\u7406\u526f\u672c\u6765\u66ff\u4ee3\u7b26\u53f7\u8fde\u63a5
shutil.rmtree( src ) \u9012\u5f52\u5220\u9664\u4e00\u4e2a\u76ee\u5f55\u4ee5\u53ca\u76ee\u5f55\u5185\u7684\u6240\u6709\u5185\u5bb9

shutil.copyfile( src, dst) \u4ece\u6e90src\u590d\u5236\u5230dst\u4e2d\u53bb\u3002\u5f53\u7136\u524d\u63d0\u662f\u76ee\u6807\u5730\u5740\u662f\u5177\u5907\u53ef\u5199\u6743\u9650\u3002\u629b\u51fa\u7684\u5f02\u5e38\u4fe1\u606f\u4e3aIOException. \u5982\u679c\u5f53\u524d\u7684dst\u5df2\u5b58\u5728\u7684\u8bdd\u5c31\u4f1a\u88ab\u8986\u76d6\u6389
shutil.move( src, dst) \u79fb\u52a8\u6587\u4ef6\u6216\u91cd\u547d\u540d
shutil.copymode( src, dst) \u53ea\u662f\u4f1a\u590d\u5236\u5176\u6743\u9650\u5176\u4ed6\u7684\u4e1c\u897f\u662f\u4e0d\u4f1a\u88ab\u590d\u5236\u7684
shutil.copystat( src, dst) \u590d\u5236\u6743\u9650\u3001\u6700\u540e\u8bbf\u95ee\u65f6\u95f4\u3001\u6700\u540e\u4fee\u6539\u65f6\u95f4
shutil.copy( src, dst) \u590d\u5236\u4e00\u4e2a\u6587\u4ef6\u5230\u4e00\u4e2a\u6587\u4ef6\u6216\u4e00\u4e2a\u76ee\u5f55\uff01

copyfile(src, dst) #src, dst 都需是文件名, 如果dst 存在或无权限,会抛出异常
copy(src, dst) #dst 可以是目录名。



扩展阅读:黑马java视频 ... python手机版下载官方 ... python shutil copyfile ... python tkinter button ... python shutil move ... python网站 ... paperpass免费入口 ... shutil模块 python ... python tkinter frame ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网