Strange compiler warning
Robin Becker
robin at jessikat.fsnet.co.uk
Thu Oct 10 12:28:46 EDT 2002
In article <3da4af97 at news.sentex.net>, Peter Hansen <peter at engcorp.com>
writes
.......
>It's not necessarily better. That's why I said both "generally",
>above, and "what are you really trying to accomplish?"
>
>Once we know exactly what you intended, it may become
>feasible to discuss which really _is_ better. Until
>then, I can say only that "except NameError" (and note
>it should NOT be just "except") is more readable _to me_
>than the lengthy expression you used. Just personal taste,
>at this point. Oh, also probably faster, since it is
>not executing two or more Python function calls to do
>the job, if that matters to you.
.... this isn't a real problem, I'm lazy and I want to do some local
debugging inside a method without putting the global into the module,
that way I can remove things without moving up and down too much.
So it's probably not an issue about speed. I was just querying whether
setting up a try/except is more complex than a dict lookup in globals().
For the two cases I see code like
6 SET_LINENO 6
9 LOAD_GLOBAL 0 (globals)
12 CALL_FUNCTION 0
15 LOAD_ATTR 1 (has_key)
18 LOAD_CONST 1 ('_dbg')
21 CALL_FUNCTION 1
24 UNARY_NOT
25 JUMP_IF_FALSE 22 (to 50)
28 POP_TOP
29 SET_LINENO 7
32 LOAD_GLOBAL 2 (open)
35 LOAD_CONST 2 ('/tmp/_dbg.txt')
38 LOAD_CONST 3 ('w')
41 CALL_FUNCTION 2
44 STORE_GLOBAL 3 (_dbg)
and
6 SET_LINENO 10
9 SETUP_EXCEPT 11 (to 23)
12 SET_LINENO 11
15 LOAD_GLOBAL 0 (_dbg)
18 POP_TOP
19 POP_BLOCK
20 JUMP_FORWARD 28 (to 51)
>> 23 SET_LINENO 12
26 POP_TOP
27 POP_TOP
28 POP_TOP
29 SET_LINENO 13
32 LOAD_GLOBAL 1 (open)
35 LOAD_CONST 1 ('/tmp/_dbg.txt')
38 LOAD_CONST 2 ('w')
41 CALL_FUNCTION 2
44 STORE_GLOBAL 0 (_dbg)
so probably the try has it since the op codes seem very simple.
--
Robin Becker
More information about the Python-list
mailing list