Skip to content
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

support for -Q switch #1239

Closed
echu79 opened this issue Jan 6, 2012 · 14 comments
Closed

support for -Q switch #1239

echu79 opened this issue Jan 6, 2012 · 14 comments
Milestone

Comments

@echu79
Copy link

@echu79 echu79 commented Jan 6, 2012

It would be very useful if support for the -Q switch could be added to both the console and the qt console version of ipython such that -Qnew would turn on new division in ipython.

Thanks

@fperez
Copy link
Member

@fperez fperez commented Jan 6, 2012

Valid request, though in the meantime you can achieve this by putting from __future__ import division to be executed at startup in your config file. See this example for details, you simply set that in the exec_lines field.

@bfroehle
Copy link
Contributor

@bfroehle bfroehle commented Jan 6, 2012

@fperez Thanks for the great tip --- I had been trying to figure out how to turn on the new division.

@echu79
Copy link
Author

@echu79 echu79 commented Jan 23, 2012

Thanks - maybe there's another setting for this, but if you were to create a script that simply did "return 1/2", and set the config in ipython from your link, running the script prints a 0. But in the actual interactive ipython session, typing 1/2 will return .5. Is there a way to apply new division to the interactive session, and any other scripts, modules that are run or imported from that ipython session?

Thank you

@fperez
Copy link
Member

@fperez fperez commented Jan 24, 2012

There is no way to set it for all imported modules, because that would most likely introduce bugs: there are many modules out there that assume the old division behavior, and if that was changed implicitly, you'd likely get weird, random crashes all over the place.

That's why the division behavior has to be explicitly indicated for each scope, at the module level and interactively.

@echu79
Copy link
Author

@echu79 echu79 commented Jan 26, 2012

Understood, but we actually desired to have the -Qnew flag be applied to all the imported modules. In the older version of ipython, we were able to achieve this by applying -Qnew to python itself in the ipython startup script before it called IPython.Shell.IPShell().mainloop(sys_exit=1)

This still seems to work in the text version of the new ipython, but was curious if this was possible with the QT version of ipython

Thanks

@fperez
Copy link
Member

@fperez fperez commented Jan 26, 2012

Ah, the issue is that we'd have to propagate that flag to the kernel start: the qt console runs the kernel in a separate process. The code that does that is in zmq/entry_point, so a quick and dirty hack for you would be to add a line with arguments.append('-Qnew') here.

We can definitely add support for this at the command-line, though. So I'll leave this open as an enhancement request, since to do it right we want to expose it so any frontend (qtconsole, text console or notebook) can use it uniformly.

@bfroehle
Copy link
Contributor

@bfroehle bfroehle commented Jan 27, 2012

Well, I think you'd actually have to put '-Qnew' earlier in the command line listing. Observe:

$ python --version
Python 2.7.2 -- EPD 7.2-2 (64-bit)
$ python -Qnew -c "print 1/2" 
0.5
$ python -c "print 1/2" -Qnew
0

(Using the -c option causes python to stop scanning the options list.)

So, something like arguments.insert('-Qnew', 1) should work.

@ellisonbg
Copy link
Member

@ellisonbg ellisonbg commented Feb 7, 2012

I am closing this as this type of thing should be handled by the user in config files.

@ellisonbg ellisonbg closed this Feb 7, 2012
@echu79
Copy link
Author

@echu79 echu79 commented Feb 7, 2012

What's the best way to achieve this functionality using the config files?

As bfroehle points out above, order matters here, so to append it to arguments in entry_point with extra_arguments won't work. And as fperez commented above, it would be nice if this option was supported as an ipython startup option and propagated properly to any frontend.

Is it possible to reopen this issue?

Thanks

@fperez fperez reopened this Feb 7, 2012
@fperez
Copy link
Member

@fperez fperez commented Feb 7, 2012

@ellisonbg, the point is that it can't be done in config files correctly, b/c it requires modifying how the interpreter itself is started. So I think it's a valid request (not a bug though)...

@ellisonbg
Copy link
Member

@ellisonbg ellisonbg commented Feb 7, 2012

Ahh, OK, feel free to reopen, but let's reclassify this as not as
Notebook related issue.

On Tue, Feb 7, 2012 at 2:30 PM, Fernando Perez
reply@reply.github.com
wrote:

@ellisonbg, the point is that it can't be done in config files correctly, b/c it requires modifying how the interpreter itself is started.  So I think it's a valid request (not a bug though)...


Reply to this email directly or view it on GitHub:
#1239 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@fperez
Copy link
Member

@fperez fperez commented Feb 8, 2012

I'd labeled it as nb and zmq and qtc, but since it more or less applies to everything, might as well just not put those labels in. I've removed them all.

@bfroehle
Copy link
Contributor

@bfroehle bfroehle commented Aug 12, 2012

Wow, -Qnew is extremely interesting. I thought it only impacted the interpreter scope but apparently it leaks to imported modules and exec'ed files:

$ cat > test.py
print(1/2)
$ python -c "import test"
0
$ python -Qnew -c "import test"
0.5
$ python -c "execfile('test.py')"
0
$ python -Qnew -c "execfile('test.py')"
0.5
@takluyver
Copy link
Member

@takluyver takluyver commented Jul 25, 2016

I don't think we can practically do this as an option on IPython, because it has to be set when the Python interpreter starts, and our command line argument handling happens inside Python.

I don't think we will do this in any Jupyter frontends, because it's something entirely specific to Python 2.

I'm therefore closing this; we can reopen it if people disagree.

@takluyver takluyver closed this Jul 25, 2016
@minrk minrk modified the milestones: no action, wishlist Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants