0

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.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Pinchanzee
1

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)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.