On Sun, Jan 15, 2012 at 7:44 PM, [email protected]
<[email protected]> wrote:
> Is there any special reason to use _filldedent instead of implicit
> concatenation of string literals?
>
> raise long_name_leaving_no_place_for_string( "blah"
> " blah blah blah blah blah blah blah blah blah"
> " blah blah blah blah blah blah blah blah blah"
> " blah blah blah blah blah blah blah blah blah") # without commas
>
> I find it nicer than _filldedent. One less function to be used. And
> it's done while compiling the .pyc.
In the case of a simple string, no. What you propose (provided you
remember to add the leading spaces) is fine. I didn't know you would
get implicit joining like that. And often these messages are not
tested so the use of _filldedent assures some level of security that
what you type won't have spacing warts. Otherwise, two reasons:
1) you don't have to fiddle with the quotation marks
2) if you plug in some expression (that you don't know the length of)
you will still get a nicely wrapped error message:
>>> raise ValueError(_filldedent('''
... This is the problem: %s''' % range(100)))
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ValueError:
This is the problem: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98,
99]
>>> raise ValueError('this is the problem'
... ' %s' % range(100))
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ValueError: this is the problem [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1
4, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 3
4, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 5
4, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 7
4, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 9
4, 95, 96, 97, 98, 99]
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.