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
__file__ is not defined when file end with .ipy #1814
Comments
Yes, see
Running a file ending with Should this be changed? |
I think it's a reasonable idea, but not very important - .ipy scripts are a convenience, and we don't want people relying on them for anything complex. |
Without this patch. I don't see the harm with having file set. People often need to know the dynamic location of the file and its name in shell scripts. part of old .sh scripts that I would like to move to IPython.
Anyways ill just rename to .py |
Well, you can rename to anything except .ipy. |
If you can just call it foo.py, absolutely do so. We don't want to encourage people to write code for IPython when standard Python code would do the job. .ipy scripts exist so you can use IPython syntax, like %magic functions and !shell commands. But I agree with you that there should be a way to find the running filename from a .ipy script. We're quite busy at the moment, but if you want to dig into the code and make a pull request, that's great. Otherwise, we'll leave this issue open, and someone will get round to it at some point. |
this patch fix the root issue. test.ipy
test2.ipy
output
running: ipython ./test.ipy seems to work well now. |
set `__file__` when running .ipy files closes #1814
Revert #1831, the `__file__` injection in safe_execfile / safe_execfile_ipy. This reverts commit 2717feb, reversing changes made to ea4f608. Pull request #1831 (fix #1814 set __file__ when running .ipy files) has been the source of a lot of grief: #2279: Setting __file__ to None breaks Mayavi import #2429: Using warnings.warn() results in TypeError In general the patch was inappropriate because it: 1. Fails to properly restore the context, by setting __file__ to None rather than deleting it. 2. Sets __file__ in the wrong dictionary (self.user_ns rather than where[0]).
Reopening as #1831 has been reverted. |
Darn now my scripts wont work again :( I wish a fix was created instead of the revert. |
I'll post something soon for you to try. |
@steverweber Can you check out #2460 ? |
@bfroehle I confirmed your commit bfcd64e will solve this issue. |
Closed by #2460. |
I am still experiencing the issue with ipython 0.13.2 :-/ ---> 13 print file |
@TheChymera that's correct, it is fixed in 1.0 (note the milestone on the Issue), which will be released this month. |
Do the non-contributor see the milestone ? |
I believe so, yes. |
I think I'm a non-contributor an I see the milestone tag at the issue heading. |
Yeah, sry, I saw that, just didn't know how to interpret it. |
No worries - in general, issues are closed when they are fixed in master. All closed issues should have a milestone (this will be None if there is no related code to change), which is generally the first release with the change (some bugfixes are backported, but not feature changes). |
…teractiveshell
…teractiveshell
set `__file__` when running .ipy files closes ipython#1814
Revert ipython#1831, the `__file__` injection in safe_execfile / safe_execfile_ipy. This reverts commit 2717feb, reversing changes made to ea4f608. Pull request ipython#1831 (fix ipython#1814 set __file__ when running .ipy files) has been the source of a lot of grief: ipython#2279: Setting __file__ to None breaks Mayavi import ipython#2429: Using warnings.warn() results in TypeError In general the patch was inappropriate because it: 1. Fails to properly restore the context, by setting __file__ to None rather than deleting it. 2. Sets __file__ in the wrong dictionary (self.user_ns rather than where[0]).
I named my IPython file.ipy
I propose .ipy ? objections ?
I feel ipython should not be confused with plain python!
Should we not trust files with different endings... I have a feeling files not ending with .py are blacklisted to prevent issues with cgi or something... not to sure.. Perhaps it has something to do with the she-bang notation..?
debian kubuntu 12.10
Thanks
The text was updated successfully, but these errors were encountered: