Re: Python: Does It Have Strict Mode Or Something?

  • From: Jamal Mazrui <empower@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Fri, 17 Jun 2011 06:17:26 -0400

Hi Richard,
Indeed, use of an uninitialized variable within a Python expression will generate a runtime error. Since the Python language does not include syntax for declaring a variable (as opposed to setting its value), however, I think there is still another kind of typo that VBScript's Option Explicit would catch but which Python would not.

Suppose I had assigned a value to a variable named "control" (spelled normally, like the word). Then suppose I later forgot that I had used the full spelling, and instead use the abbreviation "ctrl" on the left hand side of an assignment statement. JAWS reads both variable names the same, and the typo would be legal Python syntax. A runtime error would not necessarily result, yet my "control" variable would probably not have the right value.

VBScript, on the other hand, uses the "Dim" keyword to declare a variable. The typo would be caught since I presumably would not use the "Dim" keyword when assigning to the "ctrl" variable, since I thought I was just assigning the "control" variable a new value, rather than setting its initial value.

As you know, Python and other dynamic language programmers often try to catch these and other kinds of errors via different means, typically known as "unit testing."

Jamal

On 6/16/2011 10:06 AM, R Dinger wrote:
Hi Jim,
If you try to use an uninitialized variable in Python, the script will
fail with a trace and a suitable error message.
Richard
----- Original Message -----
*From:* Homme, James <mailto:james.homme@xxxxxxxxxxxx>
*To:* programmingblind@xxxxxxxxxxxxx
<mailto:programmingblind@xxxxxxxxxxxxx>
*Sent:* Thursday, June 16, 2011 6:46 AM
*Subject:* Python: Does It Have Strict Mode Or Something?

Hi,

In Perl, you can put use strict. In VB, you can put explicit on. Does
Python have something you can do to force you to initialize variables?
I'm concerned about accidental misspellings of variable names.

Thanks.

Jim

Jim Homme,

Usability Services,

Phone: 412-544-1810.


This e-mail and any attachments to it are confidential and are intended
solely for use of the individual or entity to whom they are addressed.
If you have received this e-mail in error, please notify the sender
immediately and then delete it. If you are not the intended recipient,
you must not keep, use, disclose, copy or distribute this e-mail without
the author's prior permission. The views expressed in this e-mail
message do not necessarily represent the views of Highmark Inc., its
subsidiaries, or affiliates.
__________
View the list's information and change your settings at //www.freelists.org/list/programmingblind

Other related posts: