我在Python中很新手,但是我必须为学校实现一个Python语言的命令行解释器,但我有点迷失在如何做到这一点。在Python中创建一个CLI(Shell?)
我已经看了一些教程并创建了一个简单的文件名为functions.py在那里我有一些简单的功能是这样的:
def delete(loc):
if os.path.exists(loc) == True:
os.remove(loc)
print "Removed"
else:
print "File not exists"
现在..这里是事..为了使用这个我必须将其导入python命令解释器,就像里面......
import functions
functions.delete("file to delete")
我怎样才能让一个Shell/CLI所以不是都写了这一切,我可以随便写,如:
delete file_name
谢谢!
我认为我对“CLI”的定义有所不同。你想为小编程语言(DSL)编写一个解释器,对吧? – AndiDog 2011-01-23 08:30:38