question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

%%time magic prevents assignment

See original GitHub issue

The %%time cell magic is preventing me from binding names. I found this in notebook code on Travis (py 3.6) and reproduced it locally (py 3.7) in notebook and in ipython at the terminal. It doesn’t seem to apply to all cell magics:

Python 3.7.2 | packaged by conda-forge | (default, Mar 19 2019, 20:46:22)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: %%time
   ...: foo = "bar"
   ...:
   ...:
CPU times: user 3 µs, sys: 0 ns, total: 3 µs
Wall time: 6.91 µs

In [2]: foo
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-f1d2d2f924e9> in <module>
----> 1 foo

NameError: name 'foo' is not defined

In [3]: %%prun
   ...: baz = "qux"
   ...:
   ...:
         3 function calls in 0.000 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.000    0.000 {built-in method builtins.exec}
        1    0.000    0.000    0.000    0.000 <string>:2(<module>)
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}

In [4]: baz
Out[4]: 'qux'

Confirmed that 7.3.0 worked fine locally.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:39
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
Carreaucommented, Apr 10, 2019

We’re planning to fix it as soon as we have time; it will likely make it to the 7.5 release that I’ll try to make before end of month.

2reactions
wanickcommented, Apr 2, 2019

изображение

By the way, in “%%timeit” the situation is exactly the same, but at least it behaves predictably

изображение

Read more comments on GitHub >

github_iconTop Results From Across the Web

time magic funtion prevents variable assigment when used in ...
I'm using IPython version 7.27. The following code snippet throws a NameError: name 'variable' is not defined: def test(msg): %time variable ...
Read more >
How to Keep Variable Assignment When Using %%time ...
When I run cells in Jupyter that have the %%time magic function, any variables I assign are not saved. Cell 1: %%time a...
Read more >
Combat damage step - MTG Wiki - Fandom
Attacking creatures that are blocked but have the blocking creature removed from combat before the Damage Assignment Step deal no combat damage. Attacking ......
Read more >
CR 510. Combat Damage Step - Rules Resources
No player has the chance to cast spells or activate abilities between the time combat damage is assigned and the time it's dealt....
Read more >
Administering an Assignment - Capti Voice
Stop Assignment. When you are ready to stop the assignment: Click the Magic Wand button in the top of the sidebar Select Stop...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found