[Tutor] re.compile ?? (fwd)
Wed Apr 23 17:26:01 2003
Hi Anish: I'm forwarding this to Tutor; let's keep discussion on the list
so that all of us here can help.
---------- Forwarded message ----------
Date: Wed, 23 Apr 2003 21:47:43 +0200
From: "Mehta, Anish" <Anish.Mehta@enst-bretagne.fr>
To: Danny Yoo <firstname.lastname@example.org>
Subject: Re: [Tutor] re.compile ??
from fontTools.ttLib import TTFont
from fontTools import version
print __doc__ % version
numberAddedRE = re.compile("(.*)#\d+$")
def makeOutputFileName(input, outputDir, extension):
dir, file = os.path.split(input)
file, ext = os.path.splitext(file)
dir = outputDir
output = os.path.join(dir, file + extension)
m = numberAddedRE.match(file)
file = m.group(1)
n = 1
output = os.path.join(dir, file + "#" + repr(n) + extension)
n = n + 1
I am trying to understand this code. Here dir, file is assigned the
directory and file after os.path.split(input) divides the input in two
parts of file and directory. Next if the output directory is mentioned
then output dir is assigned to dir. Then in the next line it is joined
to make the required path having output directory.
After that i m not getting what is expected from the next few lines
having match and group.
Thanks to all for giving their valuable support.
Danny Yoo wrote:
>>MA> I am not getting what should be the outcome of this line
>>MA> numberAddedRE = re.compile("(.*)#\d+$")
>>MA> I tried to read it from /usr/lib/python2.2/re.py
>>MA> But i am not getting it properly. Please suggest regarding this.
>>Something like any string that ends with # + sequences of digits:
>Can you explain what you want to get from the regular expression? The main
>problem here is that we, like Python, don't know what you expect the
>output to be. *grin*
>Are you getting an error message from your program, or is it more that the
>regex isn't detecting the patterns that you want it to detect? If you
>give us some examples of things you'd like numberAddedRE to recognize, we
>should be better able to understand the purpose of the regular expression.
>Best of wishes to you!
>Tutor maillist - Tutor@python.org