I'd like to be able to use %cd "default_dir"
and %matplotlib
whenever I call ipython
from my terminal. I tried writing this in a .py file in .ipython/profile_default/startup/file.py
but it results in the following error:
[TerminalIPythonApp] WARNING | Unknown error in handling startup files:
File "/Users/<name>/Dropbox/.ipython/profile_default/startup/startup.py", line 18
%cd "~/Dropbox/"
^
SyntaxError: invalid syntax
As a first example, you can use the magic command %lsmagic to list the available magic commands (Figure 3.11). To get the output you have to execute the cell as with any other code cell. The %load_ext magic command can be used for loading IPython extension which can add new magic commands.
The %run magic command allows you to run any python script and load all of its data directly into the interactive namespace.
Third, we use the run_line_magic() method on the ip object to run our line magic. This method takes two arguments: the name of the magic function and the remaining of the arguments for that magic. If you were in an ipython shell, this is the equivalent of running %{magic name} {magic arguments} .
You just need to use the magic in your startup scripts:
get_ipython().magic('cd ~/Dropbox')
get_ipython().magic('matplotlib')
Put that in the contents of your startup script and it should do the magic you need ✨🔮✨
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With