Problem with script and typing

Thaddeus L. Olczyk olczyk at interaccess.com
Fri Jun 9 14:28:38 EDT 2000


On Fri, 9 Jun 2000 20:59:48 +0300 (IDT), Moshe Zadka
<moshez at math.huji.ac.il> wrote:

>On Fri, 9 Jun 2000, Thaddeus L. Olczyk wrote:
>
>> 
>> Here goes ( extraneous pruned ):
>> 
>> project =[]
>> 
>> class Project:
>>        def IsNull(self):
>> 	return self.name==""
>> 	project.append(self)
>        ^^^^^ This line is never reached ???????
>
A remnant of cut and paste it was never meant to be there.
>> def FindProject(x):
>>     for project in projects:
>>         if project.name == x:
>>             return x
>>         null=Project("")
>>         projects.remove(null)
>          ^^^^^ projects are compared by identity, unless you supply an
>          __cmp__ method
>
I'm not sure exactly what you are trying to say here. The Project
constructor is supposed to insert self into the list. So if you are
trying to say the null may not be removed , I don't think so because
they are the same instance. If you mean that it would be easier to
put
           def __cmp__method(self,rhs):
                 return self.name == rhs.name
in the Projects clas, you are right. I didn't know.

>> def is_project(s):
>>     if s[len(s)-3:] == 'prj':
>>         project=FindProject(s)
>> ## error here
>>         if project.IsNull():
>>             project=Project(s)
>>         project.Scan()
>> ----------
>> error message AttributeError: 'None' object has no attribute 'IsNull'
>
>You snipped too much: how are we supposed to know what you put in the
>"projects" global variable?
>
>> 1) I've banged my head against this type of typing problem before.
>>     How do I get around it?
>
>Put correctly typed objects in containers
>
Actually it is the return x which whould have read return project.

>> 2) Is there a better way of handling null objects? ( Most languages I 
>>     know have objects which are explicitly null )
>
>None is an object which is explicitly null. What more do you need?

Thanks.



More information about the Python-list mailing list