How do I add a variable to a raw string within a loop?

373 Views Asked by At

I have the following chunk of code:

for i in range(len(files)):
    if files[i].split('^')[0]=='SequenceFile':
        number = files[i].split('^')[5]
        file = files[i].split('^')[2]
        src_path = f"C:\Users\User\Desktop\SequenceFolder\{number}\{file}"
        dst_path = f"C:\Users\User\Desktop\FinalFolder

I am getting returned the following error:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

I realize that this is because of the addition of {number} and {file} in my code, but I cannot seem to figure out how to add variable names to something like this. Any chance anyone has an idea?

Thanks!

0

There are 0 best solutions below