force variable declaration?

Peter Rams peter.rams at sap.com
Thu Oct 10 13:21:09 CEST 2002


Hi Jeff,

thanks for your answer, I meant something like this:

counter = 0
while counter < 100:
    conuter = counter + 1

leads to an endless-loop because of typing error of counter. In other
languages I have to declare all variables, it would look for example like
this:

int counter
counter = 0
while counter < 100:
   conuter = counter + 1

Then the syntax check says: no variable "conuter" declared. In Perl, for
example, there is a statement (I forgot how it's like), where you can force
the programmer to declare his variables. Is there something similar in
python?

Thanks,
Peter


"Jeff Davis" <jdavis at empires.org> wrote in message
news:6Dbp9.69869$X9.12557473 at twister.socal.rr.com...
>
> what do you mean force variable declaration? you mean type checking?
>
> You can't really force python to limit you like that. That type of
checking
> is better served by a tool independent of the interpreter. For example,
> pychecker is great for spotting probable errors in your code, even when
> the interpreter doesn't complain. See if pychecker is able to help spot
> your error.
>
> That way, we have the flexibility of python's dynamic typing, but we can
> spot our errors quickly as well.
>
> Regards,
>         Jeff
>
> > Hi,
> >
> > is it possible to force variable declaration in python (like it is for
> > example in perl)? A few days ago I had an anoying error because of a
> > typing error of a variable...
> >
> > Regards,
> > Peter
>





More information about the Python-list mailing list