runp将python函数从文件导出到命令行
runp的Python项目详细描述
runp将python函数从文件导出到命令行。 您不需要更改现有代码。
如果您有一个名为myfile.py的文件,文件名为:
def foo(): """beeps a lot""" print "beep beep" def bar(text): """Prints things Args: text (str): The text to print """ print text
您想在命令行中运行它,只需执行以下操作:
$ runp myfile.py foo beep beep
您还可以向函数传递参数:
$ runp myfile.py bar:"this is sweet!" this is sweet!
名称以\开头的函数被隐藏。
您可以使用以下命令列出可用的功能:
$ runp myfile.py -l Available functions: foo beeps a lot bar Prints things
获取有关特定功能的信息:
$ runp myfile.py -d bar Displaying docstring for function bar in module myfile bar(text) Prints things Args: text (str): The text to print
调用函数的语法为:
$ runp myfile.py function_name:arg1value,arg2=arg2value
命令和初始代码的概念、语法深受fabric任务系统的启发。