#40 backslashes in docstrings not working

devel (cvs)
closed-rejected
Edward Loper
epytext (18)
5
2014-09-13
2004-04-12
Ralf Schmitt
No

def f():
"""return C:\bla"""
pass

When running epydoc with the above file and --pdf
option, I get this error:
(/usr/local/share/texmf/tex/latex/hyperref/pdfmark.def))
(./api.aux
(./test-module.aux))
(/usr/local/share/texmf/tex/latex/hyperref/nameref.sty)
(./api.out) (./api.out)
(/usr/local/share/texmf/tex/latex/amsfonts/umsa.fd)
(/usr/local/share/texmf/tex/latex/amsfonts/umsb.fd)
(./api.toc) [1]
(./test-module.tex
! Text line contains an invalid character.
l.35 return C:^^H
la
? Output written on api.dvi (1 page, 4336 bytes).
Transcript written on api.log.
Error: latex failed: exitcode=256

Discussion

  • Edward Loper
    Edward Loper
    2004-04-12

    • status: open --> closed
     
  • Edward Loper
    Edward Loper
    2004-04-12

    Logged In: YES
    user_id=195958

    Docstrings are Python strings, and don't get any special
    treatment. In particular, "\b" in a docstring
    means "backslash" just like it does it any string. You can
    see this by printing your docstring:

    >>> print f.__doc__
    return C:^Hla

    There are two ways to fix the problem. The easier (and in
    my opinion better) way is to use a raw string. In a raw
    string, all backslashes are treated as literals. Here's your
    example with a raw string:

    def f():
    r"""return C:\bla"""
    pass

    The other option is to double all your backslashes:

    def f():
    """return C:\\bla"""
    pass

    Either way, you can test that you got it right by printing
    f.__doc__:

    >>> print f.__doc__
    return C:\bla

     
  • Edward Loper
    Edward Loper
    2004-04-12

    • labels: 577213 --> epytext
    • status: closed --> closed-rejected