f python?

Nobody nobody at nowhere.com
Sun Apr 8 19:43:49 EDT 2012


On Sun, 08 Apr 2012 04:11:20 -0700, Xah Lee wrote:

> Ok no problem. My sloppiness. After all, my implementation wasn't
> portable. So, let's fix it. After a while, discovered there's the
> os.sep. Ok, replace "/" to os.sep, done. Then, bang, all hell 
> went lose. Because, the backslash is used as escape in string, so any 
> regex that manipulate path got fucked majorly. So, now you need to 
> find a quoting mechanism.

	if os.altsep is not None:
	    sep_re = '[%s%s]' % (os.sep, os.altsep)
	else:
	    sep_re = '[%s]' % os.sep

But really, you should be ranting about regexps rather than Python.
They're convenient if you know exactly what you want to match, but a
nuisance if you need to generate the expression based upon data which is
only available at run-time (and re.escape() only solves one very specific
problem).




More information about the Python-list mailing list