Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing string with (accidental) escape character loses character even though it's a raw string
    text
    copied!<p>I have a function with a python doctest that fails because one of the test input strings has a backslash that's treated like an escape character even though I've encoded the string as a raw string. </p> <p>My doctest looks like this:</p> <pre><code>&gt;&gt;&gt; infile = [ "Todo: fix me", "/** todo: fix", "* me", "*/", r"""//\todo stuff to fix""", "TODO fix me too", "toDo bug 4663" ] &gt;&gt;&gt; find_todos( infile ) ['fix me', 'fix', 'stuff to fix', 'fix me too', 'bug 4663'] </code></pre> <p>And the function, which is intended to extract the todo texts from a single line following some variation over a todo specification, looks like this:</p> <pre><code>todos = list() for line in infile: print line if todo_match_obj.search( line ): todos.append( todo_match_obj.search( line ).group( 'todo' ) ) </code></pre> <p>And the regular expression called <code>todo_match_obj</code> is:</p> <pre><code>r"""(?:/{0,2}\**\s?todo):?\s*(?P&lt;todo&gt;.+)""" </code></pre> <p>A quick conversation with my ipython shell gives me:</p> <pre><code>In [35]: print "//\todo" // odo In [36]: print r"""//\todo""" //\todo </code></pre> <p>And, just in case the doctest implementation uses stdout (I haven't checked, sorry):</p> <pre><code>In [37]: sys.stdout.write( r"""//\todo""" ) //\todo </code></pre> <p>My regex-foo is not high by any standards, and I realize that I could be missing something here.</p> <p>EDIT: Following Alex Martellis answer, I would like suggestions on what regular expression <em>would</em> actually match the blasted <code>r"""//\todo fix me"""</code>. I know that I did not originally ask for someone to do my homework, and I will accept Alex's answer as it really did answer my question (or confirm my fears). But I promise to upvote any good solutions to my problem here :)</p> <p>EDITEDIT: for reference, a bug has been filed with the kodos project: <a href="https://sourceforge.net/tracker/?func=detail&amp;aid=2982286&amp;group_id=43860&amp;atid=437633" rel="nofollow noreferrer">bug #437633</a></p> <p>I'm using Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)</p> <p>Thank you for reading this far (If you skipped directly down here, I understand)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload