1 |
On Thu, 2008-10-30 at 16:54 -0200, Jorge Peixoto de Morais Neto wrote: |
2 |
> > To back myself up: |
3 |
> > |
4 |
> > <file name="why_no.py"> |
5 |
> > #!/usr/bin/python |
6 |
> > |
7 |
> > import random |
8 |
> > |
9 |
> > for i in range(1,10000): |
10 |
> > if random.random() < 0.001: |
11 |
> > print "rare" |
12 |
> > if malformed < beast: |
13 |
> > print "kick me in the ..." |
14 |
> > else: |
15 |
> > print "whatever" |
16 |
> > </file> |
17 |
> This kind of error is not a syntax error; this kind of error is indeed |
18 |
> only discovered at runtime. However, syntax errors are discovered at |
19 |
> byte-compile time. byte-compile happens automatically when you load a |
20 |
> module, but you can perform it yourself easily, and this is |
21 |
> recommended in certain situations. |
22 |
> |
23 |
> For this kind of error (try to reference an undefined variable), there |
24 |
> are tools like pychecker. |
25 |
> |
26 |
|
27 |
I'm coming into this thread kinda late, so feel free to ignore... |
28 |
|
29 |
... but Jorge is right. This is easily picked up by a lint tool... and |
30 |
good python programmers use them ;-). Some python-aware editors even |
31 |
have this functionality built in. |
32 |
|
33 |
Using the above example: |
34 |
|
35 |
$ pylint who_no.py |
36 |
... |
37 |
C: 1: Missing docstring |
38 |
C: 5: Comma not followed by a space |
39 |
for i in range(1,10000): |
40 |
^^ |
41 |
E: 8: Undefined variable 'malformed' |
42 |
E: 8: Undefined variable 'beast' |