Cmag
Cmag

Reputation: 15770

python display several variables after %

Folks, cant seem to remember the correct syntax for displaying 2 or more variables in the following format:

log.debug ("%s %s " % hostname % processoutput[0])

Thanks!

Upvotes: 2

Views: 65

Answers (3)

Balthazar Rouberol
Balthazar Rouberol

Reputation: 7180

You could also do:

log.debug('{0} {1}'.format(hostname, processoutput[0]))

This might look convoluted at first, but the format function is pretty powerful. See documentation and examples.

Upvotes: 2

Doug T.
Doug T.

Reputation: 65629

You want

 log.debug ("%s %s " % (hostname , processoutput[0]))

a tuple should follow the % operator listing all the params to be formatted into the string.

Upvotes: 3

Explosion Pills
Explosion Pills

Reputation: 191799

log.debug("%s %s" % (hostname, processoutput[0]))

Upvotes: 2

Related Questions