simple (?) re question

laurent8 at sxb.bsf.alcatel.fr.bbs laurent8 at sxb.bsf.alcatel.fr.bbs
Wed Jul 12 03:10:02 EDT 2000


Andrew Kuchling wrote:

> You're using the wrong tool; regexes are very clumsy for this sort of
> thing.  Try looking at your regex using Demo/tkinter/guido/redemo.py
> to see how it matches; the first .* matches '/foo/bar/SCCS/s.file',
> the ?! expression matches nothing, and the second .* matches nothing.

ok I will see this sample, but I've got a problem with the init of the
Tkinter

-----------------
Python 1.5.2 (#2, Jun 22 2000, 10:49:11)  [GCC 2.8.1] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import _tkinter
>>> import Tkinter
>>> Tkinter._test()
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File
"/users/public_w3p/share/python/Python-1.5.2/lib/python1.5/lib-tk/Tkinter.py",
line 1947, in _test
    root = Tk()
  File
"/users/public_w3p/share/python/Python-1.5.2/lib/python1.5/lib-tk/Tkinter.py",
line 886, in __init__
    self.tk = _tkinter.create(screenName, baseName, className)
TclError: Can't find a usable init.tcl in the following directories:
 



This probably means that Tcl wasn't installed properly.
-----------------

I don't know where the python interpreter try to find the init.tcl file,
in which directories
it searches.
I've put this file in a directory included in the $PYTHONLIB, but it
doesn't work as you
can see, if you have an idea...




> Similar problem; the regex engine finds an alternative match.  Why not
> just write:
>
> path, filename = os.path.split( filename )
> if 'SCCS' in string.split(path, os.pathsep):
>     # SCCS in path


I have make a sample as simple as possible in order to points out the
problem, and of course for a such simple thing I'd rather use the string
module, but my real code is more complex and I can't specialize it like
this.

> for the second?  Much clearer than a complicated regex which has to be
> analyzed to be understood, and it makes it more apparent that you're
> making a decision based on the path.

I want to use to regex module because I want to match thing like :
it begins with something "/foo" then there is something I don't care,
then I can find something like "F.?[0-9][\w*][.]/" and then something
I don't care and it will finish by a "java|py" string.
Of course, this is an example !

thanks for your answer.

--
Frédéric LAURENT
mailto:frederic.laurent at sxb.bsf.alcatel.fr
Tél : (33) 03 88 55 70 00  poste 57228



More information about the Python-list mailing list