Glenn Maynard wrote: > Here's a quick syntax file to support Python docstrings[...]
> This is a hack. It duplicates pythonString, because I'm not sure how > to reuse it. It doesn't highlight docstrings declared as raw strings > because I didn't want to duplicate pythonRawString and I can't think > of why anyone would do that, but it's legal. In can be convenient to use raw docstrings when using doctests[1] where the output has backslashes. It avoids the need to escape the backslashes in the output. For example, I've written code like the following. With a raw docstring, a blind copy-and-paste of the interpreter's output into the docstring works properly; without a raw docstring, the output must be fixed up after pasting:: #!/usr/bin/env python # Example where it's convenient to use raw docstrings. # Using non-raw docstring gives the following error unless # the backslashes in the output are escaped: # ValueError: line 7 of the docstring for __main__.joinLines # has inconsistent leading whitespace: 'two' def joinLines(lines): r"""Joins lines into one long string with newline after each line. lines -- list of lines to join. >>> joinLines(['one', 'two', 'three']) 'one\ntwo\nthree\n' """ return '\n'.join(lines) + '\n' if __name__ == '__main__': import doctest doctest.testmod() Michael Henry [1]: http://www.python.org/doc/2.5.2/lib/doctest-finding-examples.html --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---