3 ms·
Yeah, 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 prac
by famousactress 12y ago
Yeah, 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?
- klibertp 12y agoNo, unfortunately we have not. With triple quotes you get a string with newlines and indentation in it. While you can not indent the following lines it looks ugly, and you can't do anything about newlines. Take a look at how F# handles the issue: http://stackoverflow.com/a/14599828 http://stackoverflow.com/a/14599828 And CoffeeScript: http://coffeescript.org/#strings http://coffeescript.org/#strings (apparently implemented relatively recently (https://github.com/jashkenas/coffeescript/issues/3229 https://github.com/jashkenas/coffeescript/issues/3229) and borrowed from LiveScript. There are other language which support multiline strings (Here docs) with indents stripped via means of syntax, like YAML (with |), Racket (which doesn't do dedenting, but being language it is it's very easy to add) and many shells (with <<-). Python doesn't have this feature, and parse-time string literals concatenation serves this purpose. Of course, you can do something like: foo = """bar indented at first and after newline """ textwrap.dedent(foo) (or use list literals with str.join, or use a regex, or many, many other thing), but you can do this in all languages. Languages with syntactic sugar for this make writing slightly-longer-but-not-too-long strings much easier and cheaper (only done once during parsing, no need for imports, etc.), and Python makes up for not having explicit way of doing this with implicit parse-time string literals concatenation.