如何使用特殊关键字作为结构函数名称? [英] how can I use a special keyword as my fabric function name?

查看:62
本文介绍了如何使用特殊关键字作为结构函数名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用这样的保留关键字来使结构功能正常?

How can I make a fabric function with reserved keywords like this?

def not(*args):
    ......

这将引发无效语法"错误.有什么方法可以覆盖特殊关键字并将其用作经典方法中的函数名称?我可以使用@task alias 来做到这一点,但是我所有其他功能都遵循经典方法. http://docs.fabfile.org/en/1.10/usage/tasks.html#task-decorator

This throws a "invalid syntax" error. Is there any way to override the special keyword and use it as a function name in classic method? I can do this with @task alias but all my other functions follow classic method. http://docs.fabfile.org/en/1.10/usage/tasks.html#task-decorator

推荐答案

这对我来说很好:

fabfile.py

fabfile.py

from fabric.api import task

@task(alias='not')
def _not():
    print 'not called'

@task(alias='in')
def _in():
    print 'in called'

@task(alias='while')
def _while():
    print 'while called'

旧样式:

from fabric import state

def _not():
    print 'not called'

def _in():
    print 'in called'

def _while():
    print 'while called'

state.commands['not'] = _not
state.commands['in'] = _in
state.commands['while'] = _while

并运行它.

$ fab not while in
not called
while called
in called

Done.

也.下次将 python 添加到标签中时,这几乎不可能被发现"-哈哈.

Also. Next time add python to the tags, this was almost impossible to get "finded" -- haha.

这篇关于如何使用特殊关键字作为结构函数名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆