@pixelcowboy: I think Julien was asking how to detect the padding from a
filename, not a string with padding notation in it (which yours would work
for).
For safety, I would make the filename regex a little more specific, in case
there are multiple digit sequences in a filename (DI/EDL-generated names can
be nightmarish like that). Here's one option:
import re
image = 'awesome.v.001.0101.exr'
match = re.search('(\d+)\.\w+$', image)
print len(match.group(1)) if match else None
Obviously it's hard to come up with something that's totally bulletproof,
but it's nice to eliminate as many special cases as possible early on.
-Nathan
-----Original Message-----
From: [email protected]
Sent: Friday, June 10, 2011 9:23 AM
To: julien hery ; Nuke Python discussion
Subject: Re: Re : [Nuke-python] Detect padding in a filename
You can also use a wider pattern like :
r'(%+\d+d)|(#+)|(%d)'
to catch a few more cases. I highly recommend that you account for
these as you might run into problems later.
On Fri, Jun 10, 2011 at 8:31 AM, julien hery <[email protected]> wrote:
great it works like a charm!
thanks a lot
________________________________
De : Brandon Harris <[email protected]>
À : julien hery <[email protected]>; Nuke Python discussion
<[email protected]>
Envoyé le : Vendredi 10 Juin 2011 17h10
Objet : Re: [Nuke-python] Detect padding in a filename
import re
result = None
image = 'awesome.0101.exr'
number = re.search('\.(\d+)\.', image)
if number:
result = len(number.group(1))
print result
I would use regex to pull that information out.
Brandon L. Harris
On 06/10/2011 10:06 AM, julien hery wrote:
Hello,
It's more a general python question, but image related.
I'm looking at detecting the padding of a filename let's say something
like
" Filename.001.exr" would return 3
I'm having a hard time to find this answer on the web
Thanks for your help
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python