[Pythonmac-SIG] \r in string causes eval to fail

Chris Barker Chris.Barker at noaa.gov
Wed Sep 15 20:09:55 CEST 2004


Michael Hudson wrote:

> Semi-seriously, I'd guess that everyone who's bumped into this has
> found it easier to normalize the line feeds in Python than hack the
> parser (it's a little scary).

Would you need to hack the parser? I'd be inclined to simply put a 
filter in before the parser, just like I'd do in user code:

CodeString = FixLineFeeds(CodeString)
eval(CodeString)

There would be a performance issue, because you'd be doing processing 
and copying of the string before parsing it, but I wonder how often 
performance is an issue when using eval and friends.

Another question: Is there any chance that having eval and friends "fix" 
linefeeds would break existing code? I'm thinking not, but perhaps I'm 
not very imaginative. This is an issue that made universal newlines 
support in files a little more awkward.

-Chris

-- 
Christopher Barker, Ph.D.
Oceanographer
                                     		
NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov


More information about the Pythonmac-SIG mailing list