0

I have a raw string like this,

MasterFile_Name = r'C:\Users\ABC\X12345\DEF\File - Test.xlsx'

I want to pass the value of X12345 through a variable.To do that I am doing something like this

MyID = X12345

MasterFile_Name = r'C:\Users\ABC\' + MyID + '\DEF\File - Test.xlsx'

and

MasterFile_Name = r'C:\Users\ABC\' + MyID + r'\DEF\File - Test.xlsx'

They both are not working for me.

Kindly help me with this.

Siddharth Thanga Mariappan
  • 2,781
  • 11
  • 56
  • 104

1 Answers1

5

If the intention is to just concatenate it.

using str.format():

MyID = 'X12345'    
MasterFile_Name = r'C:\Users\ABC\{}\DEF\File - Test.xlsx'.format(MyID)    
print(MasterFile_Name)
DirtyBit
  • 16,151
  • 4
  • 28
  • 54