0

I want to pass a string to a variable to a string, which in turn gets passwd onto a function. I had written the code below:

Not Working

env = 'D'
myFunction("Checking Processes A%s/B%s",'')% (env,env)

error

myFunction("Checking Processes A%s/B%s",'')% (env,env)
TypeError: unsupported operand type(s) for %: 'NoneType' and 'tuple'

Since the code failed I re-wrote it as below:

Working

env = 'D'
str = "Checking Processes A%s/B%s" %(env,env)
myFunction(str,'')

Can anyone suggest any alternative shorter approaches to this ?Ideally in lines of my first attemp which would mean less LOC.

4

2 回答 2

1

Could do this:

>>> "Checking Processes A{}/B{}".format(env,env)
'Checking Processes AD/BD'
于 2013-07-11T04:27:15.223 回答
0
myFunction("Checking Processes A%s/B%s" % (env,env),'')
于 2013-07-11T04:10:11.727 回答