1

kind of new in python but enjoying it very much.

Situation: I'm writing the docstring of my functions in Python 2.7 encoding standard (ASCII i presume). I have to write \xi which of course gives me the escape error

Problem: I need to write comments which are correctly interpreted as restructured text (using rst2pdf for example). Moreover, the math part of the comments should be in latex style for later re-usage of the code. This is mandatory since for several reasons at my work place, math formulas in the eventual final report must come directly from the surge code. The usage of .. math:: \xi would be ideal since it meets both needs, if it not were for the escape error

Question: How to avoid this error? Is there a way restructuredtext-compatible to tell python to ignore or interpret in a special way the doctest? Or any way to rewrite this but without changing the latex style for the math?

Note: whatever possible modifier may be use for the comments, these can have doctest as well so is necessary to not interfere with that.

THX, any help is welcome, again kind of rookie here.

  • By "the escape error", do you mean "ValueError: invalid \x escape"? – mzjn Apr 07 '17 at 10:41
  • I haven't used that tool for generating documentation, so I am not completely sure, but I would think that using `\\x` rather than `\x` should work. – John Coleman Apr 07 '17 at 10:41
  • When you say "I need to write comments", I presume that you mean "I need to write docstrings". – mzjn Apr 07 '17 at 10:44
  • Yes I do mean "ValueError: invalid \x escape" If I write " .. math:: \\xi " I do not get the same result as " .. math:: \xi ", mainly the \xi symbol. Additionally I would be writing a non latex format – ChukerSweet Apr 07 '17 at 10:45
  • "I need to write docstrings" yes – ChukerSweet Apr 07 '17 at 10:46
  • So are you saying that John Coleman's suggestion does not work? I think you should edit the question and explain exactly what happens. – mzjn Apr 07 '17 at 10:54
  • It isn't quite clear what you are asking, but the following seems relevant. The solution in the accepted answer of using *raw strings* might also work in your case: http://stackoverflow.com/q/11765401/4996248 – John Coleman Apr 07 '17 at 11:38

0 Answers0