Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'predefined': 0.05; 'string,': 0.05; 'python': 0.08; 'backslash': 0.09; 'object.': 0.09; 'syntax': 0.11; 'am,': 0.14; 'received:209.85.214.174': 0.14; 'received:mail-iw0-f174.google.com': 0.14; 'wrote:': 0.14; '(via': 0.16; 'angelico': 0.16; 'apostrophe': 0.16; 'delimit': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mon,': 0.17; 'slightly': 0.19; 'header:In-Reply-To:1': 0.21; 'variable': 0.21; 'file,': 0.22; 'subject:problem': 0.22; 'code.': 0.22; 'issues.': 0.23; 'appear': 0.23; 'xml': 0.26; 'string': 0.26; 'object': 0.26; 'message-id:@mail.gmail.com': 0.28; 'closing': 0.28; 'received:209.85.214': 0.28; 'config': 0.30; 'equivalent': 0.31; 'andrew': 0.32; 'to:addr:python-list': 0.33; 'chris': 0.34; 'source': 0.34; 'file': 0.34; 'skip:" 10': 0.35; 'else': 0.35; 'difference': 0.37; 'received:google.com': 0.37; 'something': 0.37; 'change': 0.37; 'received:209.85': 0.37; 'another': 0.37; 'run': 0.38; 'worry': 0.38; 'subject:: ': 0.38; 'received:209': 0.39; 'containing': 0.39; 'subject:with': 0.39; 'to:addr:python.org': 0.39; 'your': 0.60; '30,': 0.84; 'composing': 0.84; 'grabbing': 0.84; 'tag,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=V49IyItcRNvKwgp1XZyXXXMDgC0y5MFP2DsVTv1YznE=; b=vrofQsBP+o0Fj4GLYvmwROTPx++LCQ04KenlMkegSdKyLOpTdQWk3Sh5oveMNEKiVC nif+SZJ3QevCJxKcp2dq4s4kzma64n/XTlHX74nsiU//7iiX/mz1WgBF5fUxUD0ZIEdT 8gnHmhf/arPTvVD6+JgYDGGIYe6L5nbY2mv18= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=mBGje1YPuB8IlHBfhdJVVEIR+VvclNjk0RBazBtc939hPQZbZJUL4drbRMn1c1vlWc YA4PSooTSLe6fVN2DVEhz5B0BTw45EQtq1C5SNDb+yhdnVt1p2c5av0cC4ZL8kvhnuUT lq/67wUi7QuHomoSR1RMDRKjPcoVvuEDUwrJI= MIME-Version: 1.0 In-Reply-To: <4DE27163.3080104@gmail.com> References: <4de2459b$0$29996$c3e8da3$5496439d@news.astraweb.com> <4de255a8$0$29996$c3e8da3$5496439d@news.astraweb.com> <1b8d81c1-ab87-4059-ad55-9f4a39331e7d@u26g2000vby.googlegroups.com> <4DE27163.3080104@gmail.com> Date: Mon, 30 May 2011 03:57:38 +1000 Subject: Re: Weird problem matching with REs From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306691862 news.xs4all.nl 49182 [::ffff:82.94.164.166]:34084 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6556 On Mon, May 30, 2011 at 2:16 AM, Andrew Berg wrote: >> Also, be sure to >> use a raw string when composing REs, so you don't run into backslash >> issues. > How would I do that when grabbing strings from a config file (via the > configparser module)? Or rather, if I have a predefined variable > containing a string, how do change it into a raw string? > "Raw string" is slightly inaccurate. The Python "raw string literal" syntax is just another form of string literal: 'apostrophe-delimited string' "quote-delimited string" """triple-quote string which may go over multiple lines""" '''triple-apostrophe string''' r'raw apostrophe string' r"raw quote string" They're all equivalent once you have the string object. The only difference is how they appear in your source code. If you read something from a config file, you get a string object directly, and you delimit it with something else (end of line, or XML closing tag, or whatever), so you don't have to worry about string quotes. Chris Angelico