问题
How can I make a fabric function with reserved keywords like this?
def not(*args):
......
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
回答1:
This looks fine to me:
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'
old style:
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
and to run it.
$ fab not while in
not called
while called
in called
Done.
Also. Next time add python to the tags, this was almost impossible to get "finded" -- haha.
来源:https://stackoverflow.com/questions/33158137/how-can-i-use-a-special-keyword-as-my-fabric-function-name