Re: Can I rely on...

2009-03-20 Thread R. David Murray
alex23 wuwe...@gmail.com wrote: On Mar 20, 1:42 am, Emanuele D'Arrigo man...@gmail.com wrote: I just had a bit of a shiver for something I'm doing often in my code but that might be based on a wrong assumption on my part. Take the following code: pattern = aPattern compiledPatterns

Re: Can I rely on...

2009-03-20 Thread Bruno Desthuilliers
pattern it will return the exact same object rather than a second, identical, object. In interactive tests via python shell this seems to be the case but... can I rely on it - always- being the case? Or is it one of those implementation-specific issues? I can't tell - I'm not willing to write

Can I rely on...

2009-03-19 Thread Emanuele D'Arrigo
but... can I rely on it - always- being the case? Or is it one of those implementation-specific issues? And what about any other function or class/method? Is there a way to discriminate between methods and functions that when invoked twice with the same arguments will return the same object and those

Can I rely on...

2009-03-19 Thread Emanuele D'Arrigo
, identical, object. In interactive tests via python shell this seems to be the case but... can I rely on it - always- being the case? If the answer is no, am I right to state the in the case portrayed above the only way to be safe is to use the following code instead? for item in compiledPatterns

Re: Can I rely on...

2009-03-19 Thread MRAB
than a second, identical, object. In interactive tests via python shell this seems to be the case but... can I rely on it - always- being the case? Or is it one of those implementation-specific issues? The re module has a cache of patterns, so if the pattern is already known then it'll return

Re: Can I rely on...

2009-03-19 Thread MRAB
Emanuele D'Arrigo wrote: [snip] If the answer is no, am I right to state the in the case portrayed above the only way to be safe is to use the following code instead? for item in compiledPatterns: if(item.pattern == pattern): print(The compiled pattern is stored.) break

Re: Can I rely on...

2009-03-19 Thread Albert Hopkins
, identical, object. In interactive tests via python shell this seems to be the case but... can I rely on it - always- being the case? Or is it one of those implementation-specific issues? And what about any other function or class/method? Is there a way to discriminate between methods and functions

Re: Can I rely on...

2009-03-19 Thread Terry Reedy
pattern it will return the exact same object rather than a second, identical, object. In interactive tests via python shell this seems to be the case but... can I rely on it - always- being the case? Or is it one of those implementation-specific issues? As MRAB indicated, this only works because

Re: Can I rely on...

2009-03-19 Thread Emanuele D'Arrigo
Thank you everybody for the informative replies. I'll have to comb my code for all the instances of item in sequence statement because I suspect some of them are as unsafe as my first example. Oh well. One more lesson learned. Thank you again. Manu --

Re: Can I rely on...

2009-03-19 Thread R. David Murray
Emanuele D'Arrigo man...@gmail.com wrote: Thank you everybody for the informative replies. I'll have to comb my code for all the instances of item in sequence statement because I suspect some of them are as unsafe as my first example. Oh well. One more lesson learned. You may have far fewer

Re: Can I rely on...

2009-03-19 Thread alex23
On Mar 20, 1:42 am, Emanuele D'Arrigo man...@gmail.com wrote: I just had a bit of a shiver for something I'm doing often in my code but that might be based on a wrong assumption on my part. Take the following code: pattern = aPattern compiledPatterns = [ ]