from cmd import *
class MyShell(Cmd):
def preloop(self):
print "print this line before entering the loop"
def postloop(self):
print "print this line after leaving the loop"
def precmd(self, line):
print "print this line before do a command"
return Cmd.precmd(self, line)
def postcmd(self, stop, line):
print "print this line after do a command"
return Cmd.postcmd(self, stop, line)
def do_test(self, line):
''' test command, just print the arguments except some special ones'''
if line == "exit":
exit()
else:
print line
MyShell().cmdloop()
[本文目的希望对于,如何在Windows下,写Python代码,进行Python开发,运行Python脚本的人,看了此文后,懂得了:什么是cmd下面去运行Python脚本;什么是Python的交互式的s
#继承cmd模块的Cmd类实现
#shell中的命令xx在类中对应的函数名为do_xx
#line是shell中输入的命令行参数