Page 1 of 1

ajax/python commentbox source

Posted: Sun Jul 03, 2011 9:25 pm
by Isaac
Source:
http://testing.isaacg.net/commentboxa/

I've given up on this one. Now that I have an idea of how to make ajax and python pass data I'm going to work on a new version that's uses classes instead of a bunch of try/except conditions, which I think are ugly!

Re: ajax/python commentbox source

Posted: Sun Jul 03, 2011 9:38 pm
by fliptw
uh... yeah, they are meant for exceptions.

try/catch isn't a good substitute for if statements.

Re: ajax/python commentbox source

Posted: Mon Jul 04, 2011 12:39 am
by Jeff250
Use "is None", "is not None" (pointer comparison) instead of "== None", "!= None" (value comparison). None is a singleton object, so this always works, and it is faster and more pythonic.

Use != instead of <>. Note that <> was finally removed in python 3.

Code: Select all

if name == '' or name == None
can be replaced with:

Code: Select all

if not name:
Use xml.sax.saxutils.escape instead of rolling your own escape function.

Code: Select all

{boxname:{date:{name:comment}}}
looks suspicious. Don't you want something like:

Code: Select all

{'date': date, 'name': name, 'comment': comment}
?

You want to use a database some day instead of pickling, but I suspect you already know that.

Re: ajax/python commentbox source

Posted: Mon Jul 04, 2011 7:20 am
by Isaac
Hmm. This might be a good time to ask.

Is using MySQL database better than saving to textfiles? I mean, so far I've never had a problem with pickling to a text file (man that sounds dirty).

Re: ajax/python commentbox source

Posted: Mon Jul 04, 2011 11:27 am
by Sirius
It's many times faster and usually more manageable, but not functionally different.