my_field = models.IntegerField(choices=MY_CHOICES)
One choice in MY_CHOICES is:
(1, 'I'm looking for...'),
I got a syntax error from that. The word "for" in the string was
treated as a reserved word.
Now if I change the single quotes to double quotes, it seems to work:
(1, "I'm looking for..."),
But the documentation only shows the single quote usage. I wonder if
it's safe to use double quotes instead. If not, what can I do to avoid
the syntax error?
Please note that you have close the quotation with a single quote right
after the character `I`, so the next few word are treated as python source
code instead of string.
Probably you would like to try:
(1, "I'm looking for..."),
or, alternatively:
(1, 'I\'m looking for...'),
------------------------
Xia Kai(夏恺)
xia...@gmail.com
http://blog.xiaket.org
--------------------------------------------------
From: "Continuation" <selfor...@gmail.com>
Sent: Sunday, December 27, 2009 4:12 PM
To: "Django users" <django...@googlegroups.com>
Subject: Is it ok to use double quotes instead of single quotes in
Field.choices?
On Dec 27, 3:18 am, Xia Kai(夏恺) <xia...@gmail.com> wrote:
> Hi,
>
> Please note that you have close the quotation with a single quote right
> after the character `I`, so the next few word are treated as python source
> code instead of string.
>
> Probably you would like to try:
>
> (1, "I'm looking for..."),
> or, alternatively:
> (1, 'I\'m looking for...'),
>
> ------------------------
> Xia Kai(夏恺)
> xia...@gmail.comhttp://blog.xiaket.org
>
> --------------------------------------------------
> From: "Continuation" <selforgani...@gmail.com>
Double quotes are absolutely fine and a lot nicer to look at than
'I\'m hard to read'.
cheers,
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
This is a python issue, and in python single and double quotes are
basically equivalent (the only constraint is that you close a string
with the quote with which you opened it). As others explained the
issue here is that your apostrophe is a single quote, closing the
string and interpreting the rest if the line as python source… which
is obviouly incorrect.