2017-07-28 50 views
1

是否有一个USB驱动器多次进行分区和格式化每个分区的使用Python 2.7.x不同类型的方式与USB驱动器?分区和格式化使用Python 2.7

编辑:使用Windows 7作为操作系统

+0

是有一种方法... :) –

+0

是的,通过系统调用。你在使用什么操作系统? – zwer

+0

我正在使用Windows 7,也将该信息添加到问题中。 – user3215564

回答

0

中,你可以使用Python subprocess与Windows的命令行工具的评论说。格式化可以使用format

来完成(Running windows shell commands with python < - 你也可以使用diskpart本)

进行分区,你可以结合一个批处理文件中使用diskpart工具。缺点是,你必须保存批处理文件的计算机

https://social.technet.microsoft.com/Forums/windows/en-US/c69d3bb5-328c-43e3-9239-837171e42b88/diskpart-batch-file?forum=w7itproinstall

与以下你可以从蟒蛇调用批处理文件

from subprocess import Popen 
p = Popen("batch.bat", cwd=r"C:\Path\to\batchfolder") 
stdout, stderr = p.communicate() 

Run a .bat file using python code