I'm not sure whether TkinterDnD2 library will return a stream of paths in a single string or single path in a string.
If it is single path in a string the solution is simple:
>>> str1="{mypath/to/file}"
>>> str1[1:-1]
The output would be
'mypath/to/file'
But I suppose your problem is multiple paths coming in single string. You can implement code as below.
Consider str1 to be string with multiple paths:
str1="{mypath1/tofile1}{mypath3/tofile3}{mypath2/tofile2}"
i=0
patharr=[]
while(str1.find('{',i)>=0):
strtIndex=str1.find('{',i)
if(str1.find('}',strtIndex+1)>0):
endIndex=str1.find('}',strtIndex+1)
patharr.append(str1[strtIndex+1:endIndex])
print(str1[strtIndex:endIndex+1])
i=endIndex+1
print(patharr)
Now the output would be as follows:
['mypath1/tofile1', 'mypath3/tofile3', 'mypath2/tofile2']
So as per your question in comment below is code for file paths which are having curly braces with in the file paths.
str1 = "{mypath}}}}1/tofil{{{e1}{mypath3/tofile3}{mypath2/tofile2}}}}}}"
i = 0
patharr = []
while (str1.find('{', i) >= 0):
strtIndexfirst = str1.find('{', i)
notFound = True
strtIndex = strtIndexfirst
while (notFound and strtIndex < len(str1)):
if (str1.find('}', strtIndex + 1) > 0):
findInd = str1.find('}', strtIndex + 1)
if (findInd == len(str1) - 1):
endIndex = str1.find('}', strtIndex + 1)
patharr.append(str1[strtIndexfirst + 1:endIndex])
print(str1[strtIndex:endIndex + 1])
i = endIndex + 1
break
if (str1[findInd + 1] == '{'):
endIndex = str1.find('}', strtIndex + 1)
patharr.append(str1[strtIndexfirst + 1:endIndex])
print(str1[strtIndex:endIndex + 1])
i = endIndex + 1
notFound = False
else:
strtIndex = findInd
else:
strtIndex = str1.find('}', strtIndex + 1)
print(patharr)
For above string output was
['mypath}}}}1/tofil{{{e1', 'mypath3/tofile3', 'mypath2/tofile2}}}}}']
If str1 is
str1="{{{mypath1/tofil}}e1}{mypath3/tofile3}{mypath2/tofile2}}}}}}"
Output is
['{{mypath1/tofil}}e1', 'mypath3/tofile3', 'mypath2/tofile2}}}}}']
Worked out for other test cases as well. This piece of code is working fine.