how to write-protect names

Lee Harr missive at frontiernet.net
Thu Sep 18 16:22:33 EDT 2003


In article <3F68CE89.20601 at aon.at>, Gregor Lingl wrote:
> Peter Hansen schrieb:
> 
>> What exactly do you need this for?  If you describe the purpose
>> you have in mind for it we can provide the best approach, or 
>> tell you that we don't think you should bother. ;-)
>> 
>> -Peter
> 
> I'm writing a module for teaching young students. It contains
> e. g. a function width, which assigns a value to some (hidden)
> variable:
> 
> >>> width(5)
> 
> Now my experience is, that from time to time some of my
> students write (erroneously)
> 
> >>> width = 5
> 
> which renders the function width unaccessible for future
> use. (Moreover the next
> 
> >>> width(10)
> 
> will result in a rather strange error-message, like
> int-object is not callable ... (my students won't
> underswtand it).
> 
> Wouldn't it be useful if the name width were write-protected
> 


Maybe you could do something with the code module
(InteractiveConsole, compile_command, etc)

You get to set up a hook that is called each time a new
input line comes in... so you could watch for your special
names and just print a helpful reminder when someone tries
to overwrite one.





More information about the Python-list mailing list