how to use concatenate a fixed string and a variable in Python

Shivam Agrawal picture Shivam Agrawal · Aug 21, 2013 · Viewed 186.1k times · Source

I want to include file name 'main.txt' in the subject for that I am passing file name from command line. but getting error in doing so

python sample.py main.txt #running python with argument 

msg['Subject'] = "Auto Hella Restart Report "sys.argv[1]  #line where i am using that passed argument

Answer

Brionius picture Brionius · Aug 21, 2013

I'm guessing that you meant to do this:

msg['Subject'] = "Auto Hella Restart Report " + sys.argv[1]
# To concatenate strings in python, use       ^