Problem with script and typing

Thaddeus L. Olczyk olczyk at interaccess.com
Fri Jun 9 14:12:04 EDT 2000


On 9 Jun 2000 17:30:19 GMT, wlav at atlas03.cern.ch (Wim Lavrijsen)
wrote:

>>def is_project(s):
>>    if s[len(s)-3:] == 'prj':
>>        project=FindProject(s)
>>## error here
>>        if project.IsNull():
>>            project=Project(s)
>>        project.Scan()
>
>Again ... 'global project'. Also, should this be a member of Project?
Actually ( now that I think of it ) since the list was supposed to be
called projects. But I don't access projects from here. Is global ( in
the other spot you suggest ) really needed?
Here is what is supposed to happen:
is_project is sent a filename. It checks whether the extension
is 'prj'. If it is it looks for it in the projects list ( FindProject
does this ). If it fails then it creates a new project ( which install
itself in the projects list). Then it calls Scan on the project.

>>2) Is there a better way of handling null objects? ( Most languages I 
>>    know have objects which are explicitly null )
>
>Yep, use None:
>
>>>> project = None
>>>> if project: print "there's a project!"
>...
>>>> if not project: print "no project!"
>...
OK. That solves the specific problem, but what about the typing
problem. Since projects only contains instances of Projects,
FindProject returns a Project. The compiler seems to complain
that it doesn't know that what FindProject returns is a project.
So I can't call specific methods on the return value.



More information about the Python-list mailing list