On 10/22/05, Jacob S. <[EMAIL PROTECTED]> wrote: > >> def nameCheck(self, value): > >> > import re > >> > tempREG = re.match('.*:.*',value) > >> > return str(tempREG) != 'None' > > This could be written better. > > def nameCheck(self, value): > tempREG = re.match('.*:.*',value) > return tempREG != None > > There's no need to convert to string. None is a type that you can check > against directly.
and even more so, a further refinement takes advantage of a single None value: return tempREG is not None this works faster than "tempREG != None" because this is an object *value* comparison (vs an object *identity* comparison). in value comparisons, the interpreter has to pull out the "value" of both objects and compare them. for identity checks, it just checks the objects themselves. this extra step saves time and improves performance. cheers, -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2006,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor