byte compiled files

Simon Callan simon at callan.demon.co.uk
Fri Jul 27 15:34:27 EDT 2001


In message <3B6127EB.2080002 at herts.ac.uk>
          Mark Robinson <m.1.robinson at herts.ac.uk> wrote:

> Thanks for the help guys, sorry I didn't include the code (what can
> I  say, duh). Anyway I did manage to fix the problem but I am still
> kinda  interested as to why I was getting that previous behaviour. I
> am running  python 2.1 under red hat 7, and python 2.1.1 under
> windows NT and had  the same problem under both. Here is the code:
> 
> def checkValidData(bsite):
> 	repeats = ['AAAA', 'CCCC', 'GGGG', 'TTTT']
> 	for x in bsite:	#check new bsite contains valid charactors
> 		if(x is not 'A' and x is not 'G' and
> 			x is not 'C' and x is not 'T' ):
> 			return 0
> 	for x in repeats:
> 		if (string.find(bsite, x) != -1):
> 			return 0
> 	return 1
> 
> Changing where I test if x is A, C, G or T by using the != test
> rather  than 'is not' solved the problem, and I guess I may have
> been using it  inappropriately, but I still don't see why it would
> have working  correctly first run and then incorrectly when working
> from the .pyc file.

I suspect that the problem is due to the interning of strings. When
loading from the .PY file, all the 'A' strings intern to the same
object, so that the 'is not' is equivalent to '!=', but when loaded
from the .PYC, the interning is done differently, so you have a
situation where x == 'A', but x is not 'A'.

Simon

-- 
http://www.callan.demon.co.uk/simon/




More information about the Python-list mailing list