os.system执行系统命令

os.system用来执行命令行

In [1]: import os
In [3]: os.system?
Signature: os.system(command)
Docstring: Execute the command in a subshell.
Type:      builtin_function_or_method

命令正确执行返回0,否则返回1:

In [5]: os.system("mkdir ")
命令语法不正确。
Out[5]: 1

#在默认路径上创建了一个testfolder文件夹。
In [6]: os.system("mkdir testfolder")
Out[6]: 0

其实选择使用os.mkdir更好:

In [4]: os.mkdir('testfolder1')

扩展:os.path.expanduser

In [6]: %paste
outputDir = os.path.expanduser('~/Desktop/test')
os.mkdir(outputDir)
 -- End pasted text --

猜你喜欢

转载自blog.csdn.net/nockinonheavensdoor/article/details/80073262