Is it possible to specify a file to run when starting QtConsole

517 views
Skip to first unread message

Ayhan Fuat Çelik

unread,
Aug 28, 2017, 1:52:18 PM8/28/17
to Project Jupyter
Hi,

When I am in the QtConsole, I can execute %run magic to run a file but I was wondering if it was possible to do the same from a terminal. (Something like ~/myDir $ jupyter qtconsole --file some_file.py)

I looked over the config file several times but I couldn't figure out a way to do it.

I am using Atom as my text editor and manually executing the %run magic each time. I am looking for a way to automate that actually. If I can do it from a terminal, I can tell Atom to execute a command when, for example, I save the file. Any pointers will be appreciated.

Thank you.

Thomas Kluyver

unread,
Aug 29, 2017, 4:22:28 PM8/29/17
to Project Jupyter
I think the simplest way to do this would be to write an IPython startup script:
http://ipython.readthedocs.io/en/stable/interactive/tutorial.html#startup-files

IPython is the kernel Jupyter uses to run Python code. Make the script check for an environment variable, and if it is set, run the file it points to. Then configure Atom to run a command like:

MY_FILE_TO_RUN=foo.py jupyter qtconsole

Ayhan Fuat Çelik

unread,
Aug 29, 2017, 7:22:37 PM8/29/17
to jup...@googlegroups.com
I added this to my startup script:

if os.environ.get('ATOM_FILE'):
    sys.path.insert(0, os.path.dirname(os.environ['ATOM_FILE']))
    module_name = os.path.splitext(os.path.basename(os.environ['ATOM_FILE']))[0]
    atom_module = __import__(module_name)

So far it seems to work. Thank you very much.

--
You received this message because you are subscribed to a topic in the Google Groups "Project Jupyter" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jupyter/rnVwI2m63cw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/CAOvn4qh17D%3DR9Nb5sA16%2BYa4UXjK6w_MTpkOiD1iAFGdHL1erw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages