Proposal for adding symbols within Python

Ben Sizer kylotan at gmail.com
Wed Nov 16 05:34:23 EST 2005


Grant Edwards wrote:
> On 2005-11-15, Ben Sizer <kylotan at gmail.com> wrote:
> >
> > myObject.value = 'value1'
> >
> > #... 100 lines of code elided...
> >
> > if myObject.value == 'Value1':
> >     do_right_thing()
> > else:
> >     do_wrong_thing()
> >
> > I don't actually think string use is 'untenable', but it is
> > definitely more error-prone. With some sort of named object on
> > the right hand side you will at least get a helpful NameError.
>
> I don't see how that's an argument in favor of the proposal
> being discussed.  Aren't $Value1 and $value1 both legal and
> distinct symbols in the proposed syntax?  Won't you have the
> exact same issue that you do with mis-typing strings?

I think the idea is that if the symbol hasn't been instantiated locally
in an assignment operation, then it will not exist, and "if foo ==
$symbolName" will either raise a NameError or flag some error during
compilation. It cannot do this with string comparisons.

I expect this would require a 2-pass compilation process, the first
pass spotting all references to symbols and instantiating them
appropriately, the second pass resolving these references and noting
any that did not match up.

-- 
Ben Sizer




More information about the Python-list mailing list