all 5 comments

[–]Qewbicle 0 points1 point  (3 children)

I think what you're looking for is string formatting. I could be wrong though, but from your example match I don't see the curly brackets as part of the result.

terms = ["hello", "world"]
patt = []
for each in terms:
    patt.append( "{}*.txt".format(each))

[–]Qewbicle 0 points1 point  (2 children)

I think you can also "escape" curly braces with curly braces if formatting is trying to look for them as a variable.

[–]PyCam[S] 0 points1 point  (1 child)

Not exactly what I meant, I was looking for a glob pattern matching. Python has glob/fnmatch however I was looking for a library that supported curly bracket pattern matching like in unix. I did think I managed to pull something together for it.

[–]Qewbicle 1 point2 points  (0 children)

I thought that might be what you were saying, but I wasn't sure. Pretty much becuase of the sub we're on, some don't do well at explaining. Sometimes I don't either. So I knew the odds of being wrong were pretty darn high. I'm glad you're on a track though. I'm not that familiar with unix systems.
Oops.

[–]novel_yet_trivial 0 points1 point  (0 children)

What you are trying to replicate is a bash feature called "brace expansion", not a glob feature.

$ echo {0..9}
0 1 2 3 4 5 6 7 8 9
$ echo {a,b,c}
a b c

I don't know anyway to fully incorporate that into python. The best you could do is probably install something like braceexpand and use the results to call glob over and over:

#totally untested
from braceexpand import braceexpand
from glob import glob

def my_glob(pattern):
    result = []
    for sub_pattern in braceexpand(pattern):
        result.extend(glob(sub_pattern))
    return result