I totally agree with you, and it was silly from me to do it in the first place (in fact, I triggered the problem while cleaning up my code).
Modifying what you're iterating is a terrible practice most of the times, and punishment is deserved. Nevertheless that's valid Python code, and the segmentation fault could a bit too much. Since I would expect an exception to be raised in such cases, I was wondering if the segFault can be prevented. If not, then it's good to know that that loop is lethal, that's it. On 04/28/2015 03:25 PM, Dimitri Maziuk wrote: > On 04/28/2015 04:50 PM, Stefano Forli wrote: > >> Now, I understand that a segFault shouldn't happen, but I'm not sure >> what would be the way to prevent it. Is this a bug or something that >> nobody should ever do (and it should be added to the documentation)? > > It's something nobody should ever do: python iterators are objects and > what happens if you modify the value is anybody's guess. (With native > containers it's usually a shallow copy of the element in a temp. value > which gets overwritten on the next iteration. With other kinds of > containers it may open a portal to asgard and brain-eating alien zombies > start pouring in.) > > Index-based accesses should work though. Try > for i in len( pmol.atoms ) : > ... use pmol.atoms[i] ... > -- Stefano Forli, PhD Staff Scientist Molecular Graphics Laboratory Dept. of Integrative Structural and Computational Biology, MB-112F The Scripps Research Institute 10550 North Torrey Pines Road La Jolla, CA 92037-1000, USA. tel: +1 (858)784-2055 fax: +1 (858)784-2860 email: fo...@scripps.edu http://www.scripps.edu/~forli/ ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ OpenBabel-discuss mailing list OpenBabel-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbabel-discuss