Python questions from C/Perl/Java programmer

Paul Wright paul-wright at verence.demon.co.uk
Wed Jul 26 18:38:41 EDT 2000


In article <397CC80C.43F5D8 at alabanza.net>, ye, wei <yw at alabanza.net> wrote:
>Remco Gerlich wrote:
>
>> ye, wei wrote in comp.lang.python:
>>
>> > 2. Why variable doesn't have to be declared before use?
>>
>> Because it's not necessary!
>
>I can bear the {} issue, however I couldn't bear with variable without
>declaration.  I wrote many applications, I couldn't live without
>declaration. For big project, there are so many scripts, everyone may
>be misspell variable name.  It's very timeconsume and hard to find out
>such problem, which should be easy checked out by compiler.

This may be silly question, but you do realise that Python's behaviour
is not equivalent to Perl's here, don't you? (Perl without "use strict",
that is). In Perl, if you refer to an unitialised variable it takes on
the value zero. In Python, to do that is an error.

Of course, that won't catch things like this:

mispelling = 1
misplling = mispelling + 1

but it's a convenient middle ground between Perl's "strict" behaviour
and Perl's default behaviour.

-- 
----- Paul Wright ------| "No problem is too big it can't be run away from"
-paul.wright at pobox.com--| 	-- Linus
http://pobox.com/~pw201 | 



More information about the Python-list mailing list