[EMAIL PROTECTED] wrote: > I do it with all the separate variables mainly for performance. If I > had the headers in a dict, I'd be looking up a string in a list of > strings (the keys of the dict) everytime I check for a header. Not > that that's going to take more that 0.1 seconds, but the program is > still small and simple. As it gets bigger, more features are gonna > slow things down.
As I just said in my other post, this is all premature optimization. Make your program simple and clear up front, and then work on spot-optimizations in the places that your code really is slow. Premature optimization can kill you in terms of code reliability and maintainability. The rule of thumb is that 80% of your program's execution time will be in 20% of the code. Therefore you have to profile the code and fine out exactly where this 20% is. Then you can optimize it. Another thing to consider is that referencing a member of a class or instance already *is* a dictionary lookup. It's how python works. Thus dictionaries are optimized to be fast. Since strings are immutable, python hashes them into a fast lookup pointer. So every time you say mydict["mykey"], it already knows the lookup pointer (hash) for "mykey" (the string) and can find the dictionary entry very quickly, ideally in O(1) time (well maybe log(N)). Thus putting your headers in a dictionary is actually a really good idea for performance reasons. -- http://mail.python.org/mailman/listinfo/python-list