Reputation: 426
I'm trying to use var value in file.write function:
profile = open("/tmp/%s.pcf", 'w+') % uid
and I get this error:
TypeError: unsupported operand type(s) for %: 'file' and 'str'
Any idea what I'm doing wrong?
Upvotes: 0
Views: 324
Reputation: 28036
You need the string format inside
profile = open("/tmp/%s.pcf" % uid, 'w+')
Upvotes: 1
Reputation: 1121256
Move the string formatting operand to the string itself:
profile = open("/tmp/%s.pcf" % uid, 'w+')
You were trying to apply it to the result of the open()
call, which is a file.
Upvotes: 5