My internet browsing skills have failed me and I can't seem to find any solution to this. I image it'll be easy for you guys though and I'd be incredibly grateful if you could help me. I'm new to Python so a relatively simple explanation would do me very well, if possible!

Best for me to explain via example, I'm trying to write this to a file.

new.write("Error - invalid first qualifier (Line ", counter, ")\n", item)

Hoping that it would read:
Error - invalid first qualifier (Line 3)
{incorrect text here}

Can I write that in a manner in which I don't have to express it like this?:

new.write("Error - invalid first qualifier (Line ")
new.write(counter)
new.write(")\n")
new.write(item)

I get the "x arguments expected, y given" error when doing it the former way. Latter works fine.
Can't seem to find any way to easily concatenate these with a simple function.

Thanks in advance.

Recommended Answers

All 2 Replies

write() takes a string parameter
concatenation needs string types
so try this ...

counter = 3
item = "milk"

s = "Error - invalid first qualifier (Line " + str(counter) + ")\n" + item
print(s)  # test for write(s)

That worked a treat, thanks very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.