map/filter/reduce/lambda opinions and background unscientific mini-survey
Ron Adam
rrr at ronadam.com
Wed Jul 6 11:18:31 EDT 2005
Dan Sommers wrote:
> On Wed, 06 Jul 2005 14:33:47 GMT,
> Ron Adam <rrr at ronadam.com> wrote:
>
>
>>Since this is a Python 3k item... What would be the consequence of
>>making None the default value of an undefined name? And then assigning
>>a name to None as a way to delete it?
>
>
> [ ... ]
>
>
>>Any drawbacks?
>
>
> Lots more hard-to-find errors from code like this:
>
> filehandle = open( 'somefile' )
> do_something_with_an_open_file( file_handle )
> filehandle.close( )
>
> Regards,
> Dan
If do_something_with_an_open_file() is not defined. Then you will get:
TypeError: 'NoneType' object is not callable
If "file_handle" (vs "filehandle") is None. Then you will still get an
error as soon as you tried to use the invalid file handle.
AttributeError: 'NoneType' object has no attribute 'read'
If the error was filehundle.close() you will get:
AttributeError: 'NoneType' object has no attribute 'close'
I don't think any of those would be hard to find.
Cheers,
Ron
More information about the Python-list
mailing list