Python equivalent of 'use strict'

Steve Holden sholden at holdenweb.com
Tue Jan 16 18:49:14 EST 2001


"Hamish Lawson" <hamish_lawson at yahoo.co.uk> wrote in message
news:94232r$297$1 at nnrp1.deja.com...
> David Lees wrote:
>
> > Is there an equivalent to the perl 'use strict'? [My perl/C++ guru
> > friend] is concerned with accidentally initializing values of
> > mistyped variables. I showed him how you get an error doing an
> > operation with an uninitialized variable ... but he is looking for
> > this 'use strict' stuff.
>
> Python effectively has "use strict" on all the time and all assignments
> effectively use "my".

 [ ... ]

> (though I concede that using 'my' on both assignments is not quite
> idiomatic Perl). Similarly, Python won't stop you saying:
>
>     foo = 2
>     fooo = foo + 1
>
> where you meant
>
>     foo = 2
>     foo = foo + 1
>
Of course in 2.0 you would write

        foo += 1

and you would get an error if you tried

        fooo += 1

instead. This is a bonus I hadn't envisaged when considering augmented
asignments.

regards
 Steve





More information about the Python-list mailing list