Title says it all, I need to log two strings in one line.
For example, something like this:
logging.info(string1,string2)
Thank you :)
The logging functions act like this:
result = arg1 % (arg2, arg3, ...)
What you have will try to format the first string with the second string:
result = string1 % string2
Either manually specify a formatting string:
logging.info('%s %s', string1, string2)
Or join them together into one string:
logging.info(' '.join([string1, string2]))
string1 + string2.Using f strings, you could turn this into a one-liner and make it quite readable.
# python3 f-strings
logging.info(f'{string1} {string2}')
logger.info("String 1: {0!r} --- String 2: {1!r}".format(string1, string2))
Demo:
>>> print "String 1: {0!r} --- String 2: {1!r}".format('hello', 'world')
String 1: 'hello' --- String 2: 'world'
>>> print "String 1: {1!r} --- String 2: {0!r}".format('world', 'hello')
String 1: 'hello' --- String 2: 'world'
Two things to note here: