-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Builtin __file__ does not work in Interactive Console #3443
Comments
This is a behavior that is a side effect of running on the IPython Console. In that case there isn't really a file defined. One possible way to address this would be to auto-define a file variable, but this could have unexpected side effects. |
@greazer I completely disagree with your assessment. It is not a side effect of running in an IPython console. I can execute this same file in IPython (not Jupyter Notebook) via the %run command or straight from a command prompt and Furthermore, it's really handy to be able to use Can we please reopen this issue? |
@greazer @IanMatthewHuff Can we please revisit this issue? Again, file is available within an IPython console. @IanMatthewHuff I believe this is related to your proposed fix to issue microsoft/vscode-python#5460 . |
That code does work if you use %run and the name of a file. It doesn't work from a cell though. I think we could fix this though by setting the |
@rchiodo Out of curiosity, why not just use the %run command when a user runs an entire file? |
We'd have to special case the creation of the code in the output then. Because the code in the '%run' case would literally be '%run <your file>'. |
Interesting. I'd actually be quite alright with that in the case of running a whole file. I already have the code in front of me (in the file), I don't really need it duplicated in the interactive terminal. Additionally, Spyder and Matlab don't dump the entire contents of the file (although collapsed in this case) into the terminal, so it would be a very familiar feel for most scientific programmers. Just a thought. |
I would really appreciate setting the |
Fixed as part of some of the native editor work |
The builtin file variable is not defined in the python interactive window. The following code will not run in the interactive window, but it will run when executed in the terminal:
I get a NameError where 'file' is not defined.
The text was updated successfully, but these errors were encountered: