A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/attachments/20150125/7e17c44c/attachment.html below:

<div dir="ltr">Perfect, thanks!</div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 25, 2015 at 7:08 AM, Petr Viktorin <span dir="ltr"><<a href="mailto:encukou@gmail.com" target="_blank">encukou@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Sun, Jan 25, 2015 at 12:55 PM, Neil Girdhar <<a href="mailto:mistersheik@gmail.com">mistersheik@gmail.com</a>> wrote:<br>
> How do I disassemble a generated comprehension?<br>
><br>
> For example, I am trying to debug the following:<br>
><br>
>>>> dis.dis('{**{} for x in [{1:2}]}')<br>
>  Â 1  Â  Â  Â  Â  Â 0 LOAD_CONST  Â  Â  Â  Â  Â  Â  Â 0 (<code object <dictcomp> at<br>
> 0x10160b7c0, file "<dis>", line 1>)<br>
>  Â  Â  Â  Â  Â  Â  Â 3 LOAD_CONST  Â  Â  Â  Â  Â  Â  Â 1 ('<dictcomp>')<br>
>  Â  Â  Â  Â  Â  Â  Â 6 MAKE_FUNCTION  Â  Â  Â  Â  Â  0<br>
>  Â  Â  Â  Â  Â  Â  Â 9 LOAD_CONST  Â  Â  Â  Â  Â  Â  Â 2 (2)<br>
>  Â  Â  Â  Â  Â  Â  12 LOAD_CONST  Â  Â  Â  Â  Â  Â  Â 3 (1)<br>
>  Â  Â  Â  Â  Â  Â  15 BUILD_MAP  Â  Â  Â  Â  Â  Â  Â  1<br>
>  Â  Â  Â  Â  Â  Â  18 BUILD_LIST  Â  Â  Â  Â  Â  Â  Â 1<br>
>  Â  Â  Â  Â  Â  Â  21 GET_ITER<br>
>  Â  Â  Â  Â  Â  Â  22 CALL_FUNCTION  Â  Â  Â  Â  Â  1 (1 positional, 0 keyword pair)<br>
>  Â  Â  Â  Â  Â  Â  25 RETURN_VALUE<br>
><br>
> (This requires the new patch in issue 2292.)<br>
><br>
> The code here looks fine to me, so I need to look into the code object<br>
> <dictcomp>.  How do I do that?<br>
<br>
</div></div>Put it in a function, then get it from the function's code's constants.<br>
I don't have the patch applied but it should work like this even for<br>
the new syntax:<br>
<br>
>>> import dis<br>
>>> def f(): return {{} for x in [{1:2}]}<br>
...<br>
>>> dis.dis(f)<br>
  1  Â  Â  Â  Â  Â 0 LOAD_CONST  Â  Â  Â  Â  Â  Â  Â 1 (<code object <setcomp> at<br>
0x7ff2c0647420, file "<stdin>", line 1>)<br>
  Â  Â  Â  Â  Â  Â  3 LOAD_CONST  Â  Â  Â  Â  Â  Â  Â 2 ('f.<locals>.<setcomp>')<br>
  Â  Â  Â  Â  Â  Â  6 MAKE_FUNCTION  Â  Â  Â  Â  Â  0<br>
  Â  Â  Â  Â  Â  Â  9 BUILD_MAP  Â  Â  Â  Â  Â  Â  Â  1<br>
  Â  Â  Â  Â  Â  Â 12 LOAD_CONST  Â  Â  Â  Â  Â  Â  Â 3 (2)<br>
  Â  Â  Â  Â  Â  Â 15 LOAD_CONST  Â  Â  Â  Â  Â  Â  Â 4 (1)<br>
  Â  Â  Â  Â  Â  Â 18 STORE_MAP<br>
  Â  Â  Â  Â  Â  Â 19 BUILD_LIST  Â  Â  Â  Â  Â  Â  Â 1<br>
  Â  Â  Â  Â  Â  Â 22 GET_ITER<br>
  Â  Â  Â  Â  Â  Â 23 CALL_FUNCTION  Â  Â  Â  Â  Â  1 (1 positional, 0 keyword pair)<br>
  Â  Â  Â  Â  Â  Â 26 RETURN_VALUE<br>
>>> f.__code__.co_consts[1]  # from "LOAD_CONST 1"<br>
<code object <setcomp> at 0x7ff2c0647420, file "<stdin>", line 1><br>
>>> dis.dis(f.__code__.co_consts[1])<br>
  1  Â  Â  Â  Â  Â 0 BUILD_SET  Â  Â  Â  Â  Â  Â  Â  0<br>
  Â  Â  Â  Â  Â  Â  3 LOAD_FAST  Â  Â  Â  Â  Â  Â  Â  0 (.0)<br>
  Â  Â  Â  >>  Â  6 FOR_ITER  Â  Â  Â  Â  Â  Â  Â  12 (to 21)<br>
  Â  Â  Â  Â  Â  Â  9 STORE_FAST  Â  Â  Â  Â  Â  Â  Â 1 (x)<br>
  Â  Â  Â  Â  Â  Â 12 BUILD_MAP  Â  Â  Â  Â  Â  Â  Â  0<br>
  Â  Â  Â  Â  Â  Â 15 SET_ADD  Â  Â  Â  Â  Â  Â  Â  Â  2<br>
  Â  Â  Â  Â  Â  Â 18 JUMP_ABSOLUTE  Â  Â  Â  Â  Â  6<br>
  Â  Â  Â  >>  Â 21 RETURN_VALUE<br>
</blockquote></div><br></div>

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4