ajax/python commentbox source

For all coding issues - MODers and programmers, HTML and more.

Moderators: Jeff250, fliptw

Post Reply
User avatar
Isaac
DBB Artist
DBB Artist
Posts: 7737
Joined: Mon Aug 01, 2005 8:47 am
Location: 🍕

ajax/python commentbox source

Post 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!
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-★ ·:*¨༺꧁༺ :E ༻꧂༻¨*:·.★-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6459
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Re: ajax/python commentbox source

Post by fliptw »

uh... yeah, they are meant for exceptions.

try/catch isn't a good substitute for if statements.
User avatar
Jeff250
DBB Master
DBB Master
Posts: 6539
Joined: Sun Sep 05, 1999 2:01 am
Location: ❄️❄️❄️

Re: ajax/python commentbox source

Post 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.
User avatar
Isaac
DBB Artist
DBB Artist
Posts: 7737
Joined: Mon Aug 01, 2005 8:47 am
Location: 🍕

Re: ajax/python commentbox source

Post 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).
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-★ ·:*¨༺꧁༺ :E ༻꧂༻¨*:·.★-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
User avatar
Sirius
DBB Master
DBB Master
Posts: 5616
Joined: Fri May 28, 1999 2:01 am
Location: Bellevue, WA
Contact:

Re: ajax/python commentbox source

Post by Sirius »

It's many times faster and usually more manageable, but not functionally different.
Post Reply