[Tutor] re.compile ?? (fwd)
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
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 <dyoo@hkn.eecs.berkeley.edu>
Subject: Re: [Tutor] re.compile ??
import sys
import os
import getopt
import re
from fontTools.ttLib import TTFont
from fontTools import version
def usage():
print __doc__ % version
sys.exit(2)
numberAddedRE = re.compile("(.*)#\d+$")
def makeOutputFileName(input, outputDir, extension):
dir, file = os.path.split(input)
file, ext = os.path.splitext(file)
if outputDir:
dir = outputDir
output = os.path.join(dir, file + extension)
m = numberAddedRE.match(file)
if m:
file = m.group(1)
n = 1
while os.path.exists(output):
output = os.path.join(dir, file + "#" + repr(n) + extension)
n = n + 1
return output
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.
Regards,
Anish MEHTA.
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:
>>dpwufhuwefbe[#123, etc.
>>
>>
>
>Hi Anish,
>
>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
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
>