Static Typing in Python
Gonçalo Rodrigues
op73418 at mail.telepac.pt
Sat Mar 13 10:46:52 EST 2004
On Sat, 13 Mar 2004 14:55:08 +0000 (GMT), Premshree Pillai
<premshree_python at yahoo.co.in> wrote:
> --- Terry Reedy <tjreedy at udel.edu> wrote: >
>> "Premshree Pillai" <premshree_python at yahoo.co.in>
>> wrote in message
>> > Anyway, what I want is to force variable
>> declaration.
>> > In perl we have the "use strict vars" pargma...I
>> need
>> > something like that...
>>
>> For those of us who do not know Perl, and there are
>> many, I suspect, on
>> this Python newsgroup, that means nothing ;-).
>>
>> tjr
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
>Yes. Let me explain. Perl's "strict" pragma makes sure
>that you have declared (initialized) a variable before
>using it. Nothing more to it.
>
I don't know a thing about perl, but by your description, strict
pragma is to solve a problem *in perl that does not exist in Python*.
If you use a variable before declaring (I'm using your terminology --
it's not the most correct in the Python world, though) Python just
raises an exception, e.g.
>>> #No var declared... exception raised:
>>> print var
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
NameError: name 'var' is not defined
>>> #Declare var:
>>> var = "Declared"
>>> print var
Declared
>>>
With my best regards,
G. Rodrigues
More information about the Python-list
mailing list