Discussion:
[Fab-user] variable substitution
Jeff Honey
2018-04-17 15:27:25 UTC
Permalink
So, I've been trying to add some more intelligence to my Fabric functions and am running into difficulties.

Say, I wanted to include env.host string as a variable into a put() call.

def myput():
myvar=env.host_string
put('/source/$myvar-*','/mydest/', mode=0644)

...which returns a ValueError.

if I try this, as I would with a runtime argument.

def myput():
myvar=env.host_string
put('/source/%s-*','/mydest/' % myvar)

...which returns a Type Error.

Is there a simple way to overcome my lack of python knowledge here?

--
€€€€€€€€€€€€€€€€€€
€ kyoboku kazeoshi €
€€€€€€€€€€€€€€€€€€
Brandon Whaley
2018-04-17 15:45:17 UTC
Permalink
In the first example, you're trying to use a format method that is not
supported in python. In your second example, you're using the format
operator on the second string instead of the first in the put call. Here's
what you should do:

def myput():
myvar = env.host_string
put('/source/%s-*' % myvar, '/mydest/')
So, I’ve been trying to add some more intelligence to my Fabric functions
and am running into difficulties.
Say, I wanted to include env.host string as a variable into a put() call.
myvar=env.host_string
put(‘/source/$myvar-*’,’/mydest/’, mode=0644)

which returns a ValueError.
if I try this, as I would with a runtime argument.
myvar=env.host_string
put(‘/source/%s-*’,’/mydest/’ % myvar)

which returns a Type Error.
Is there a simple way to overcome my lack of python knowledge here?
--
€€€€€€€€€€€€€€€€€€
€ kyoboku kazeoshi €
€€€€€€€€€€€€€€€€€€
_______________________________________________
Fab-user mailing list
https://lists.nongnu.org/mailman/listinfo/fab-user
Jeff Honey
2018-04-17 20:07:05 UTC
Permalink
Duh. I should have seen that one coming. The replacement happens on the string immediately preceeding. Brilliant. Very similar to the way printf() works.

Thanks, again, Brandon.

From: Brandon Whaley <***@gmail.com>
Sent: Tuesday, April 17, 2018 11:45 AM
To: Jeff Honey <***@pona.net>
Cc: fab-***@nongnu.org
Subject: Re: [Fab-user] variable substitution

In the first example, you're trying to use a format method that is not supported in python. In your second example, you're using the format operator on the second string instead of the first in the put call. Here's what you should do:

def myput():
myvar = env.host_string
put('/source/%s-*' % myvar, '/mydest/')

On Tue, Apr 17, 2018 at 11:28 AM Jeff Honey <***@pona.net<mailto:***@pona.net>> wrote:
So, I’ve been trying to add some more intelligence to my Fabric functions and am running into difficulties.

Say, I wanted to include env.host string as a variable into a put() call.

def myput():
myvar=env.host_string
put(‘/source/$myvar-*’,’/mydest/’, mode=0644)


which returns a ValueError.

if I try this, as I would with a runtime argument.

def myput():
myvar=env.host_string
put(‘/source/%s-*’,’/mydest/’ % myvar)


which returns a Type Error.

Is there a simple way to overcome my lack of python knowledge here?
--
€€€€€€€€€€€€€€€€€€
€ kyoboku kazeoshi €
€€€€€€€€€€€€€€€€€€


_______________________________________________
Fab-user mailing list
Fab-***@nongnu.org<mailto:Fab-***@nongnu.org>
https://lists.nongnu.org/mailman/listinfo/fab-user
Loading...