[Tutor] python shell not working like it used to

Alan Gauld alan.gauld at btinternet.com
Mon Feb 26 10:02:50 CET 2007


"Jeff Peery" <jeffpeery at yahoo.com> wrote 

>      def __init__(self, other):
>        d['this'] = other.this
>   
>  "other" here is the dictionary I pass in (I think), 
> so it's for some reason looking for some attribute in 
> my dictionary called 'this'. 

other is whatever you pass in.
The code expects it to be dictionary like and to 
have a this attribute

> of course my dictionary doesn't have this attribute. 

So why is your code trying to access one if you know 
it doesn't exist? And why are you surprised at the 
error message? (Or is the init() not your code?)

> I have no idea what this is. any ideas? 

Youu seem to have answered your own question.
You are passing a dictionary into init() that does not 
have a this attribute but the code inside the init() is 
trying to access a this attribute. It can't find one so 
it raises an error.

Either remove the this access in init or add a thus 
attribute to your dictionary argument. Or pass an 
argument that does have a this attribute.

I'm slightly confused about what you are asking us to tell you?

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list