0

I have one string that is build based on some parameter as following. What is the best way for me to do it so I can build the string based on parameter and when I pass argument, I do not need to use xxxx{}xxx{}.format('{}', '{}')

def func(_st, **kwargs):
    if 'b' in kwargs:
        return _st.format(kwargs['b'], 'c')
    if 'c' in kwargs:
        return _st.format('b', kwargs['c'])

_var = 'sss'
_sA = func('aaa{}/bb{}/cc{}'.format(_var, '{}', '{}'), b=1)
_sC = func('aaa{}/bb{}/cc{}'.format(_var, '{}', '{}'), c=3)
print(_sA)
print(_sC)
##
_sA = aaasss/bb1/ccc
_sB = aaasss/bbb/cc3
sangbe1192
  • 54
  • 8
  • Are you asking how to have `{}` in the output from `format()`? – jwodder Apr 25 '17 at 19:42
  • for string ```func('aaa{}/bb{}/cc{}'.format(_var, '{}', '{}'), b=1)```. i need to pass {} as parameter so i can use format in the method func to format string again.. do i have a better way to do it? – sangbe1192 Apr 25 '17 at 19:57

0 Answers0