Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

python - 如何在Python中复制文件?(How do I copy a file in Python?)

How do I copy a file in Python? (如何在Python中复制文件?)

I couldn't find anything under os . (我在os下找不到任何东西。)

  ask by Matt translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

shutil has many methods you can use. (shutil有很多方法可以使用。) One of which is: (其中之一是:)

from shutil import copyfile

copyfile(src, dst)

Copy the contents of the file named src to a file named dst . (将名为src的文件的内容复制到名为dst的文件。) The destination location must be writable; (目标位置必须是可写的;) otherwise, an IOError exception will be raised. (否则,将IOError异常。) If dst already exists, it will be replaced. (如果dst已经存在,它将被替换。) Special files such as character or block devices and pipes cannot be copied with this function. (特殊文件(例如字符或块设备和管道)无法使用此功能进行复制。) src and dst are path names given as strings. (srcdst是以字符串形式给出的路径名。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...