4 ms·
This list is an excellent summary. If tasked with a #11 I'd probably add the slightly more obscure, but still super painful (when you do run into it) implicit s
by famousactress 12y ago
This list is an excellent summary. If tasked with a #11 I'd probably add the slightly more obscure, but still super painful (when you do run into it) implicit string concatenation:
>>> l = ["a",
... "b",
... "c"
... "d"]
>>> l
['a', 'b', 'cd']
- yeukhon 12y agoI never knew you could do that. You don't need the continuation though. >>> l = ["A", "c""d"] >>> l ['A', 'cd']
- mark-r 12y agoYou don't need the continuation, but that's where you're most likely to make the mistake. It'll catch you when you leave off the comma from the last element of the list, then go back later and add another element to the end.
- yeukhon 12y agoSorry, I am not followed. Can you show it instead? Thanks!
- ColinWright 12y agoYou need to re-format that with leading spaces to retain the indentation.
- nine_k 12y agoStill hugely useful when you want to write long string constants. Imho, adding a comma after each list element is a good practice. You can easily swap them, add more, and never run into a an issue you describe: foo = [ "a", "bc", "def", # comma here, too ]
- fragmede 12y agoThis is preferred! (It also makes diffs more readable)
- famousactress 12y agoI totally agree, but if you have javascript folks on your team you run into issues with this... (thanks IE!)
- nulltype 12y agoCoffeescript!
- bluecalm 12y agoYou could easily use a + operator then. I find the behavior surprising. I would expect a syntax error. You get a syntax error if you write two integers next to each other (separated by a space) or two of any other thing but somehow "a" "b" got converted to "ab". If I've discovered it myself I would be tempted to fill a bug report. It goes against Python mantra: "Explicit is better than implicit" It seems someone thought along similar lines and took action: http://legacy.python.org/dev/peps/pep-3126/ http://legacy.python.org/dev/peps/pep-3126/ but the issue got rejected.
- famousactress 12y agoYeah, when I discovered this little "feature" I had a read through that. The folks that use this for blocks of multi-line text are very defensive about the practice. I do understand not wanting to break compatibility though, especially since finding instances of this is hard (which is another reason it shouldn't exist in the first place!). Oh well :)
- tripzilch 12y ago> The folks that use this for blocks of multi-line text are very defensive about the practice. odd, because we have triple-quotes for that, don't we?