[Tutor] Multi-line code that uses \ in doctest
Don Taylor
nospamformeSVP at gmail.com
Tue Feb 6 18:21:26 CET 2007
When I try to use something like:
>>> hexStringNums = ('1', '2', '3', '4', '5', '6',\
... '7', '8', '9','0')
or:
>>> for hexString in hexStrings:
... for x in hexString:
... if ((not x in hexStringChars) and
... (not x in hexStringNums)):
... print hexString+ \
... " is not a hex string."
... break
in doctest (Python 2.4) I get an invalid syntax error around the line
continuation marker, e.g.
Failed example:
hexStringNums = ('1', '2', '3', '4', '5', '6',...
'7', '8', '9','0')
Exception raised:
Traceback (most recent call last):
File "C:\PYTHON24\lib\doctest.py", line 1243, in __run
compileflags, 1) in test.globs
File "<doctest __main__[1]>", line 1
hexStringNums = ('1', '2', '3', '4', '5', '6',...
'7', '8', '9','0')
^
SyntaxError: invalid syntax
I can fix this by not using \ line continuations, but is there a way to
get doctest to parse these lines as I expect?
Thanks,
Don Taylor
More information about the Tutor
mailing list