我真的需要它以某种方式工作:
from fabric.api import *
from fabric.contrib import *
def test():
global env
env.user = 'vagrant'
env.hosts = ['127.0.0.1', ]
env.port = 2222
env.key_filename = "/Users/sscarduzio/.vagrant.d/insecure_private_key"
run('ls /')
测试用例:
$ fab test
No hosts found. Please specify (single) host string for connection:
我不明白为什么可以在函数外部更改 env.* 的值,并且一旦在函数(或类)结构中构造我的代码就会忽略它。
谢谢!
最佳答案
不要使用import *
,也不要使用全局变量。两者都没有必要。
from fabric.api import env, run
def test():
env.user = 'vagrant'
env.hosts = ['127.0.0.1', ]
env.port = 2222
env.key_filename = "/Users/sscarduzio/.vagrant.d/insecure_private_key"
run('ls /')
关于python - 为什么我无法在函数内更改 env.hosts?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20518785/