There are two answers here:
Firstly, for super simple functions like above, you can define them in exec_lines , for example:
c.InteractiveShellApp.exec_lines = [ "def f(s): print s" ]
(you can define arbitrarily complex functions this way, but this is annoying in a couple of lines)
For more complex code, you can write a script that you want to run at startup and add it to the exec_files list:
c.InteractiveShellApp.exec_files = [ "/path/to/myscript.py" ]
We realized that this is a little annoying, so at 0.12 there will be an autoload folder in the profile directories, and everything you enter there will be launched automatically. This essentially adds extra glob.glob('*.py') to exec_files (which you can do yourself in 0.11, of course).
source share