Don’t flame but I’m still a python newbie. I need to suppress the carriage return after I display a variable.
data = """
[virtual_machines: %s]
\taddress %s.domain.com
""" % (line, line)
fg = file('munin.txt', 'a')
fg.write(stuff)
When printing this out, it creates a new line after the variable gets printed. I tried using %r but that displays the “\n” code.
Edit: I’m actually trying to write it into another file.
If I understand your question correctly, you are seeing a new-line after the %s. It looks like
linemay have a newline in it, in which case you can doline.strip()to remove all whitespace around it:or
If you are seeing an unwanted newline at the end of the whole thing, it is because you have a newline in your multi-line string and should refer to Jared Updike’s answer.