On 11/14/11 00:27, Mike Dewhirst wrote:
I have been using the Python line continuation symbol +\ in my models
help_text when my text goes beyond column 80 in my editor.

I just accidentally omitted it for a continued line and discovered it
doesn't seem to be needed!!!

Is that a feature of Django's admin app or a trap for the unwary?

It's a python feature.

http://docs.python.org/reference/lexical_analysis.html#string-literal-concatenation

Outside Django, you can see it in the following:

>>> x = ("stuff"
... "morestuff"
... "yetmorestuff"
... )
>>> print x
stuffmorestuffyetmorestuff
>>> {"hello"
... "world": "value"
... "rest of value"
... }
{'helloworld': 'valuerest of value'}
>>> ["list"
... "with"
... "one"
... "element"
... ]
['listwithoneelement']


Strings that abut inside a continuation context (parens, brackets or braces) are combined together at parsing time. The only thing to watch out for is the obvious lack of characters inserted, so you'll want to make sure any spaces/newlines you want get put in the strings:

>>> s = ("space after this " # you can even include comments
...   "so that this reads right")
>>> print s
space after this so that it reads right

(as opposed to "space after thisso that it reads right")

So what you're seeing is the continuation context of parens used in the call to a *Field object:

  class MyModel(Model):
    foo = CharField(
      ...,
      help_text="Some help here "
      "that continues on the next line"
      )

Perfectly reliable and quite helpful at times.

-tim


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to