These are chat archives for ipython/ipython

23rd
Aug 2016
Nahuel
@D3f0
Aug 23 2016 17:13
Hi there, anyone knows about some magic command to run C code? Like Bitey but something that just calls gcc -cx -o fooo - (stdin), runs and print the output?
I took a look at https://github.com/ipython/ipython/wiki/Extensions-Index but I don't find anything that fits my needs.
Now I'm writing three cells, like this:
%%writefile main.c
#include <stdio.h>
int main(void) {
    printf("Hello world\n");
    return 0;
}
---------------
!gcc main.c -o main
!./main
Damian Avila
@damianavila
Aug 23 2016 18:15
@D3f0 there is a C kernel: https://github.com/brendan-rius/jupyter-c-kernel I don't know the status of the codebase...
Nahuel
@D3f0
Aug 23 2016 18:32
@damianavila that's looks kind of what I need. Would I loose IPython magic functions using that code?
Fernando Perez
@fperez
Aug 23 2016 18:34
It looks like it's really a pure-C kernel, so yes, you'd lose all Python functionality. It would be interesting if that tool was also made available as a magic to embed it into regular IPython sessions (in addition to being usable as a standalone kernel).
Though it might be easier to just write a little magic for yourself that does basically what you show above...
Nahuel
@D3f0
Aug 23 2016 18:38
@fperez I agree. I'm teaching a subject that is mostly C (first three months), and then OpenCL (PyOpenCL). I decided to use IPython right from the very begining. It's easier for me if the students hand in ipynb's
Fernando Perez
@fperez
Aug 23 2016 18:40
Interesting... If you're really focused on C, then installing that C kernel might be a good solution, and just use it next to regular IPython notebooks for the more Python-based work..
Nahuel
@D3f0
Aug 23 2016 18:42
Yes, that would be a nice approach. I'd like to run some stats (like what Bitey does in it's README.md) and do some plotting of the performance of each algorithm
I would need a way to "rescue" the binaries from the kernel and run them with some sort of %%timeit like tool
Nathan Goldbaum
@ngoldbaum
Aug 23 2016 19:27
@D3f0 the cython magic does more or less that for cython (also makes the cython functions defined in a code cell get exposed to the IPython runtime)
maybe you could take a look at that?
it's bundled with cython
Fernando Perez
@fperez
Aug 23 2016 19:43
@D3f0, see here for a quick and dirty implementation: https://gist.github.com/fperez/60bb699660d6909d41c6ba4e04f3a2de
kwankyu
@kwankyu
Aug 23 2016 21:36
TerrminalInteractiveShell.readline_parse_and_bind
I am sorry to distract your discussions. But I don't know any other place to ask this question. In the latest IPython version, it seems that the configuration option "TerrminalInteractiveShell.readline_parse_and_bind" is removed. I wonder if it is moved to other place. Then where? If it is removed, then why? I am sorry again to distract.
Fernando Perez
@fperez
Aug 23 2016 21:43
IPython doesn't use readline anymore, it now uses prompt_toolkit: http://ipython.readthedocs.io/en/stable/whatsnew/version5.html
That brings a lot of new functionality that was impossible with readline, but it means some old, readline-based configuration isn't possible anymore, sorry!
kwankyu
@kwankyu
Aug 23 2016 21:47
Hmm. That is disappointing. It means a feature(http://doc.sagemath.org/html/en/reference/repl/sage/repl/readline_extra_commands.html) in Sage does not work anymore. Anyway thanks for reply!
Fernando Perez
@fperez
Aug 23 2016 21:49
Yes, sorry. While it's disappointing in that direction, it made a lot of other really nice things possible. As always, it's a compromise :)
kwankyu
@kwankyu
Aug 23 2016 21:51
Yes, I see the cool features now in Sage :-) Great!!