0

Strange problem here. If I use fabric.operations.prompt to get the value of a variable, it appears to store it just fine. However, it's confusing my while loop.

Here is the code setting the variable manually:

def test():
    #var1 = fabric.operations.prompt("Var1:")
    var1 = 3
    var2 = 1
    while (var1 > var2):
        print("hi")
        var2 = var2 + 1
        print("var2: %s" % var2)
        print("var1: %s" % var1)

Not surprisingly, the output is:

[me@host]$ fab test
hi
var2: 2
var1: 3
hi
var2: 3
var1: 3

Done.

However, if I change my code to be:

def test():
    var1 = fabric.operations.prompt("Var1:")
    var2 = 1
    while (var1 > var2):
        print("hi")
        var2 = var2 + 1
        print("var2: %s" % var2)
        print("var1: %s" % var1)

The output is something like the below. Caught it as soon as I could, it executed extremely fast.

var1: 3
hi
var2: 34567
var1: 3
hi
var2: 34568
var1: 3
hi
var2: 34569
var1: 3
hi
var2: 34570
^C
Stopped.

This loop is telling me that 3 > 34570. That's not true. I think this is fabric-specific and something with the .prompt operation.

This has to be a variable, I can't set it manually.

Vincent Savard
  • 34,979
  • 10
  • 68
  • 73
  • 1
    [`fabric.operations.prompt`](http://docs.fabfile.org/en/1.10/api/core/operations.html#fabric.operations.prompt) probably returns a string and not an int. Comparing a `str` and an `int` does some [pretty weird things](http://stackoverflow.com/questions/3270680/how-does-python-compare-string-and-int) in Python 2. – Vincent Savard Feb 24 '16 at 16:05
  • That was it, thanks! – Carl_Friedrich_Gauss Feb 24 '16 at 16:24

0 Answers0