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.

`runfile` resets namespace

See original GitHub issue

I runfile a lot, and just noticed that it doesn’t involve re-running the startup script. Is this intended? It’s rather self-defeating if I must restart the kernel each time for startup functions to be available (or for arbitrary scripts to execute).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
impact27commented, Nov 23, 2020

As I said, running the startup script after every runfile by default could be a bit confusing. For example if you set a variable myvar in the startup script and in the file you run, you would not be able to preserve the script’s myvar. As a workaround I would advise that the startup script adds whatever you want to keep to the builtins module. That way it will survive the reset, which is really what you want:

import builtins
def myfunc(): print(0)
builtins.myfunc = myfunc
%reset
myfunc()
0
0reactions
OverLordGoldDragoncommented, Nov 23, 2020

Fair enough. And interesting bot you have there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: runfile() got an unexpected keyword argument ...
This will be fixed in Spyder 5.1.2. In the meantime, downgrade the ipykernel package in the environment to 6.2.0:
Read more >
IPython Console — Spyder 5 documentation
The IPython Console allows you to execute commands and interact with data inside IPython interpreters. Spyder IPython Console with code, inline plots, and...
Read more >
I am using spyder and am getting an error when trying to ...
Hi, i am currently working on spyder and am getting an error message (see below) when trying to import the module.
Read more >
Untitled
runfile ('/Users/progprim/Desktop/lecture05-exceptions.py', ... exec(compile(f.read(), filename, 'exec'), namespace) ... In [84]: %reset.
Read more >
Spyder - the Python IDE — Computational Science and Data ...
2.1 Switch to an IPython console; 2.2 Reset the name space; 2.3 Strive for PEP8 ... In [1]: runfile('/Users/fangohr/Desktop/hello.py', ...
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