Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'languages.': 0.04; '(except': 0.07; '*not*': 0.07; 'source.': 0.07; 'string': 0.09; 'combines': 0.09; 'escape': 0.09; 'fixed,': 0.09; 'literal': 0.09; 'skip:\\ 10': 0.09; 'python': 0.11; 'mostly': 0.14; '"b"': 0.16; 'arbitrary.': 0.16; 'backslash': 0.16; 'backslash,': 0.16; 'backslashes': 0.16; 'be:': 0.16; 'character.': 0.16; 'hardcoded': 0.16; 'literal,': 0.16; 'mode,': 0.16; 'newlines': 0.16; 'skip:\\ 30': 0.16; 'special.': 0.16; 'string:': 0.16; 'stuff.': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'rules': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'either.': 0.24; 'string,': 0.24; '(or': 0.24; 'header:In-Reply-To:1': 0.27; 'character': 0.29; 'code': 0.31; 'getting': 0.31; 'usually': 0.31; '>>>>': 0.31; 'object.': 0.31; 'file': 0.32; 'compatible': 0.32; 'regular': 0.32; 'quite': 0.32; 'raw': 0.33; 'there,': 0.34; 'could': 0.34; 'but': 0.35; 'should': 0.36; 'two': 0.37; 'same.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'explain': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'even': 0.60; 'read': 0.60; 'dave': 0.60; 'places': 0.64; 'different': 0.65; 'charset:windows-1252': 0.65; 'reads': 0.68; 'received:74.208': 0.68; 'results': 0.69; 'special': 0.74; 'angel': 0.91; 'same,': 0.91 Date: Mon, 02 Mar 2015 18:23:05 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: rst and pypandoc References: <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:6LZ1yrdiBTDZuNDUgl1rTqmTvC3QfUu+iXGvZzPDYFC 7tBjmhPMqzLvzpfn7bYke9MaE/wtuMu3uR+1rRacWMKO/tmlcm wbUfqhx7v7cfQwfY3p0gk7nxxYy0EKF+PFtCsYXjAzNo2MuONL IQaVKtIkaV1WBjQPTEvKN3aPnQv6GSCDOOvHl7Tap8WK21dvnh 96+UAr0LElwzpnDie9NGY6vvDcV+fPhOuQuReJdcPW+3UzeobQ 3CqgEWc2uCUKIFfuGrKz2FcTmHL7YS6WoAB9wfJXXlGXjBMHGa h52HGa9y97NMg2fUVDOdDF39gWlUgzgRvlyWim7lYUn6jBOp2q vsuohy4DlbBzfoVv+0h4= X-UI-Out-Filterresults: notjunk:1; X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 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: 65 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1425339347 news.xs4all.nl 2941 [2001:888:2000:d::a6]:57084 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86795 On 03/02/2015 05:40 PM, alb wrote: > Hi Dave, > > Dave Angel wrote: > [] >>>> or use a raw string: >>>> >>>> i = r'\\ref{fig:abc}' >> >> Actually that'd be: >> i = r'\ref{fig:abc}' > > Could you explain why I then see the following difference: > > In [56]: inp = r'\\ref{fig:abc}' print inp and you should get \\ref{fig:abc} > > In [57]: print pypandoc.convert(inp, 'latex', format='rst') > \textbackslash{}ref\{fig:abc\} > > > In [58]: inp = r'\ref{fig:abc}' print inp and you should get \ref{fig:abc} This is NOT the same. The rules are not arbitrary. They're quite necessary, and it's the same for lots of different languages. When in a regular literal, the backslash is an escape character that combines with the following character. When in a raw literal, the backslash is a backslash, unless it's at the end of the string, in which case it's not the end of the string, it's an escaped quotation. (Or something. Just don't use *trailing* backslash in a raw literal) > > In [59]: print pypandoc.convert(inp, 'latex', format='rst') > ref\{fig:abc\} > > The two results are clearly *not* the same, even though the two inp > /claim/ to be the same... > When I said backslashes are not special in data read from a file, I should also say neither are quotes, or tabs, or anything else. Python just reads them in, and stuffs them into a string object. Newlines are special if you use readline(), but if you use read(), they're not special either (except on MSDOS compatible variants, which use two bytes for newline. Even there, if you read a file in "b" mode, they're not special either. So your code is going to mostly be getting strings from files, or from calculations, and these backslashes won't be special. It's only in *testing* that you usually deal with this literal stuff. Or in places where the data is fixed, and hardcoded in the source. -- DaveA