Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86736
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| 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; 'python.': 0.02; 'python,': 0.02; '(at': 0.04; 'output': 0.05; 'string.': 0.05; 'string': 0.09; '101': 0.09; 'character,': 0.09; 'converted': 0.09; 'doing?': 0.09; 'escape': 0.09; 'indicates': 0.09; 'oh,': 0.09; 'output,': 0.09; 'wrong,': 0.09; 'python': 0.11; '"in"': 0.16; '"some': 0.16; 'backslash': 0.16; 'be:': 0.16; 'carriage': 0.16; 'elsewhere.': 0.16; 'escapes': 0.16; 'for,': 0.16; 'formatted': 0.16; 'integer.': 0.16; 'languages)': 0.16; 'literal.': 0.16; 'restructured': 0.16; 'semantics': 0.16; 'string:': 0.16; 'symbols': 0.16; 'followed': 0.16; 'appropriate': 0.16; 'wrote:': 0.18; '(not': 0.18; 'variable': 0.18; 'file,': 0.19; 'normally': 0.19; 'practices,': 0.19; 'help.': 0.21; 'input': 0.22; 'programming': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'format,': 0.24; 'text,': 0.24; 'text.': 0.24; 'question': 0.24; 'this:': 0.26; 'least': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'am,': 0.29; 'character': 0.29; "doesn't": 0.30; "i'm": 0.30; "skip:' 10": 0.31; 'argue': 0.31; "d'aprano": 0.31; 'lies': 0.31; 'noted': 0.31; 'steven': 0.31; 'work:': 0.31; 'probably': 0.32; 'supposed': 0.32; 'another': 0.32; 'text': 0.33; 'becomes': 0.33; 'raw': 0.33; 'maybe': 0.34; 'something': 0.35; 'convert': 0.35; 'hundreds': 0.35; 'but': 0.35; 'there': 0.35; 'i.e.': 0.36; 'doing': 0.36; "i'll": 0.36; 'searching': 0.37; 'clear': 0.37; 'convention': 0.38; 'generic': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'explain': 0.39; 'does': 0.39; 'embedded': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'above,': 0.60; 'simply': 0.61; 'first': 0.61; "you've": 0.63; 'show': 0.63; 'name': 0.63; 'more': 0.64; 'charset:windows-1252': 0.65; 'combining': 0.68; 'received:74.208': 0.68; 'risk': 0.72; 'inline': 0.74; '102': 0.84; 'circles': 0.84; 'me).': 0.84; 'or...': 0.84; 'received:74.208.4.194': 0.84; 'terrible': 0.84; 'tricky': 0.84; 'journey': 0.93 |
| Date | Mon, 02 Mar 2015 09:08:17 -0500 |
| From | Dave Angel <davea@davea.name> |
| 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 | <cliji5FvctU1@mid.individual.net> <54f458a5$0$13003$c3e8da3$5496439d@news.astraweb.com> <clj866F68tpU1@mid.individual.net> |
| In-Reply-To | <clj866F68tpU1@mid.individual.net> |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:ljbqzR6A+EbJwjXZ2vWGX4NoKUwW8VhnrxVNwKW1tCw O87dy06jgoi4MhTPpjvJk4QJrPS2hUKlVDAwDbwCMKEWFzpwBe 2gsi7LSIhLxh83FOykSdA50adVgYzTXDFXLJ/Y+718tOkJ6R4K UOH5Dr8IphIDqu9IM9CrT6i3ijQ51P0OndvUMaZ8D3EqvTXxWQ lX8yxxSuUclIiMaW3jkjHikgIO0fweZgmKlh0avNfXz4mVDpME mx6o5LBu3TyS4MZs0YpU4Vgihxsq6D0TlHpCoxMr8cQpCSd12l tjmbJRqHf8o0lcG+IT4TCGsFQO6p/piMI4Vek8kVGDA8WXuKq7 igZkEUedu2etsDV0ZOZg= |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.39.1425305311.13471.python-list@python.org> (permalink) |
| Lines | 95 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1425305311 news.xs4all.nl 2850 [2001:888:2000:d::a6]:51312 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:86736 |
Show key headers only | View raw
On 03/02/2015 08:51 AM, alb wrote:
> Hi Steven,
>
> Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
> []
>> Since \r is an escape character, that will give you carriage return followed
>> by "ef{fig:abc".
>>
>> The solution to that is to either escape the backslash:
>>
>> i = '\\ref{fig:abc}'
>>
>>
>> or use a raw string:
>>
>> i = r'\\ref{fig:abc}'
Actually that'd be:
i = r'\ref{fig:abc}'
>
> ok, maybe I wasn't clear from the very beginning, but searching for a
> solution is a journey that takes time and patience.
>
> The worngly named variable i (as noted below), contains the *i*nput of
> my text which is supposed to be restructured text. The output is what
> pypandoc spits out after conversion:
>
> i = "\\begin{tag}{%s}{%s}\n %s\n \\end{tag}" % (some, restructured, text)
> o = pypandoc.convert(i, 'latex', format='rst')
>
> Now if i contains some inline text, i.e. text I do not want to convert
> in any other format, I need my text to be formatted accordingly in order
> to inject some escape symbols in i.
>
> Rst escapes with "\", but unfortunately python also uses "\" for escaping!
Only when the string is in a literal. If you've read it from a file, or
built it by combining other strings, or... then the backslash is just
another character to Python.
>
>>
>> Oh, by the way, "i" is normally a terrible variable name for a string. Not
>> only doesn't it explain what the variable is for, but there is a very
>> strong convention in programming circles (not just Python, but hundreds of
>> languages) that "i" is a generic variable name for an integer. Not a
>> string.
>
> I'm not in the position to argue about good practices, I simply found
> more appropriate to have i for input and o for output, considering they
> are used like this:
>
> i = "some string"
> o = pypandoc.convert(i, ...)
> f.write(o)
>
> with very little risk to cause misunderstanding.
How about "in" and "out"? Or perhaps some name that indicates what
semantics the string represents, like "rst_string" and "html_string"
or whatever they actually are?
>
>> Can you show what you are doing? Escaping the backslash with another
>> backslash does work:
>>
>> py> for c in '\\ref':
>> ... print(c, ord(c))
>> ...
>> \ 92
>> r 114
>> e 101
>> f 102
>>
>> so either you are doing something wrong, or the error lies elsewhere.
>
> As said above, the string is converted by pandoc first and then printed.
> At this point the escaping becomes tricky (at least to me).
>
> In [17]: inp = '\\ref{fig:abc}'
>
> In [18]: print pypandoc.convert(inp, 'latex', format='rst')
> ref\{fig:abc\}
>
What did you expect/desire the pyandoc output to be? Now that you don't
have the embedded 0x0a, is there something else that's wrong?
If it's in the internals of pyandoc, I'll probably be of no help. But
your first question was about escaping; I'm not sure what it's about now.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 07:59 +0000
Re: rst and pypandoc Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2015-03-02 12:03 +0100
Re: rst and pypandoc Dave Angel <davea@davea.name> - 2015-03-02 07:03 -0500
Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 12:36 +0000
Re: rst and pypandoc Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-02 23:33 +1100
Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 13:51 +0000
Re: rst and pypandoc Dave Angel <davea@davea.name> - 2015-03-02 09:08 -0500
Re: rst and pypandoc Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-03 01:43 +1100
Re: rst and pypandoc Dave Angel <davea@davea.name> - 2015-03-02 13:55 -0500
Re: rst and pypandoc Ben Finney <ben+python@benfinney.id.au> - 2015-03-03 06:09 +1100
Re: rst and pypandoc Dave Angel <davea@davea.name> - 2015-03-02 14:16 -0500
Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 22:30 +0000
Re: rst and pypandoc Chris Angelico <rosuav@gmail.com> - 2015-03-03 09:51 +1100
Re: rst and pypandoc Ben Finney <ben+python@benfinney.id.au> - 2015-03-03 10:18 +1100
Re: rst and pypandoc Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-03 10:32 +1100
Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-03 20:35 +0000
Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 22:40 +0000
Re: rst and pypandoc Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-02 23:08 +0000
Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-03 20:37 +0000
Re: rst and pypandoc Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-03 10:22 +1100
Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-03 20:46 +0000
Re: rst and pypandoc Dave Angel <davea@davea.name> - 2015-03-02 18:23 -0500
Re: rst and pypandoc MRAB <python@mrabarnett.plus.com> - 2015-03-02 14:37 +0000
Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-02 22:37 +0000
Re: rst and pypandoc Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-03-03 19:40 +1300
Re: rst and pypandoc al.basili@gmail.com (alb) - 2015-03-03 20:50 +0000
Re: rst and pypandoc Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-03-04 11:27 +1300
Re: rst and pypandoc MRAB <python@mrabarnett.plus.com> - 2015-03-02 14:40 +0000
Re: rst and pypandoc Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-03 02:09 +1100
csiph-web