Problem with script and typing

Moshe Zadka moshez at math.huji.ac.il
Fri Jun 9 13:59:48 EDT 2000


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 ???????

> 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

> 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

> 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?
--
Moshe Zadka <moshez at math.huji.ac.il>
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com





More information about the Python-list mailing list