1
act = input("Enter name of the activity") cellone = int(input("Enter the order number of activity")) cell1 = "A" + cellone worksheet.write(cell1, act) 

I'm trying to concatenate A and cellone but I'm getting some error saying that I can't concatenate string and an integer, is there a way to do this?

1
  • You don't actually need to concatenate the string and integer. The XlsxWriter write() function take integer values as well as strings so you could just do this: worksheet.write(cellone -1, 0, act). See the XlsxWriter docs: xlsxwriter.readthedocs.io/worksheet.html#worksheet-write Commented Mar 20, 2022 at 14:17

4 Answers 4

3

You can change int to a string representation using this:

cell1="A"+str(cellone) 

Alternatively, f-string formatting will also work:

cell1=f"A{cellone}" 
Sign up to request clarification or add additional context in comments.

3 Comments

I agree with this answer. f-string is a preferred way for Python as of now. Not only it's cleaner, it's faster as well.
@IamThuYa indeed it's faster and easy, but still a "hack". In a professional environment where thousands of lines are reviewed and maintained, it's very important to maintain the logic behind the writing. In the first case the developer shows that he's casting a string in order to concat with 'A', while in the second it's like reformatting the variable.
@CommissarVasiliKarlovic I agree with maintaining the logic but this is not a "hack". For python at least, we care about pythonic ways. Using f-string provide so much more control over plain casting. If the variable is a float, with f-string I can control how many decimal I want to use, etc.
1

str(cellone) returns the value of cellone as a string.

call1="a"+str(cellone) 

Comments

1

Remove the int in line 2 as follows:

cellone=input("Enter the order number of activity")

It takes the input as a string data type anyway

Comments

1

Just dont convert the string to int. correct that to

cellone=input("Enter the order number of activity") 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.