Re: When to use a model property vs. method?
On 17 juin, 21:24, Micky Hulse <rgmi...@gmail.com> wrote:
>
> I have never used the @classmethod decorator before. I will have to
> read up on that one.
A classmethod is a method that takes the class itself as first
argument, and so can be called either on a class or instance. It's
very handy for alternate constructors or such and some interesting
patterns...
> Looks like there's also @staticmethod... Interesting stuff! Thanks!
Well, Python is 100% OO in that everything you can bind to a name is
an object (classes, functions, modules etc), but it's not "pure" OO in
that it doesn't force you into using classes when you just don't need
them. This makes the staticmethod much less useful, since most of the
time a plain function will be enough.
>
> I am reminded of a sidebar that I read in the Dive Into Python book:
>
> "There are no constants in Python."
Nope but there's another very strong convention here: ALL_UPPER_NAMES
are to be considered as constants.
> " Everything can be changed if you
> try hard enough. This fits with one of the core principles of Python:
> bad behavior should be discouraged but not banned. If you really want
> to change the value of None, you can do it,"
That's not true anymore FWIW:
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> None = 42
File "<stdin>", line 1
SyntaxError: assignment to None
>>>
but you can still do some other very weird things like:
>>> False = True
>>> False
True
> " but don't come running to
> me when your code is impossible to debug."
Indeed.
>
> > Well, I usually redirect this kind of questions to c.l.py, since it's
> > about Python and not Django...
>
> I have not hear of c.l.py... I assume that it is a Python listserv?
Usenet newsgroup comp.lang.python. You can also access it via
googlegroups too.
> Also, thanks for pointing towards the wiki:
>
> http://wiki.python.org/
>
> That site looks useful.
http://python.org/doc/ should be your starting point.
HTH
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home