On 08 novembre 09:26, Omega Weapon wrote: > On 08/11/12 08:31, Sylvain Thénault wrote: > >On 07 novembre 20:00, Omega Weapon wrote: > >>On 07/11/12 07:34, afayolle wrote: > >>>I have not looked in depth as the code, but msg[0][0] will throw an > >>>IndexError if len(msg[0]) == 0, whereas the above code will set msgType > >>>to an empty list. > >>> > >>>Using msgType = msg[0][:1] will work regardless of len(msg[0]) (since > >>>slices never generate IndexError). > >> > >>Thanks for the responses - back on this now. I completely missed the > >>latter fact - thanks afayolle... not even a need for an if! So the > >>whole problem is solved with the '[:1]'. > >> > >>https://bitbucket.org/OmegaPhil/pylint/changeset/a9c692e0329069ab75f2e915ac017cd2e3a6502b > >>has now been committed. > > > >Fine, but I can't think of a case where message type will be an empty string. > >Not a big deal though. > > > > That isnt the point - it copes with both a single character msgtype > and one with the ID appended at the same time, no if needed.
It is somewhat the point: msg[0][0] is more readable than msg[0][1:], to me at least. Difference being the second option is resilient to empty string, so one may ask if this empty string case may occur or not. -- Sylvain Thénault, LOGILAB, Paris (01.45.32.03.12) - Toulouse (05.62.17.16.42) Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations Développement logiciel sur mesure: http://www.logilab.fr/services CubicWeb, the semantic web framework: http://www.cubicweb.org _______________________________________________ Python-Projects mailing list [email protected] http://lists.logilab.org/mailman/listinfo/python-projects
