1,234
edits
Changes
→Using Magic Functions
:#Lets find out which ones are available, type the following command into the IPython shell:<source>
alias
</source>We should now have a list of all the bash commands available in IPython. Shortly, we will go over how to add new bash commands into this environment, but you must remember that these commands are only here to assist in your python scripting - we are NOT here to learn bash commands.<br><br>:#Next lets add a new bash command that seems to be missing from this list:<source> alias vim vim</source>:#Run the vim command to see that it works, then exit your vim editing session without saving.:#The vim command will give us our much needed syntax highlighting, while we are editing scripts from within the IPython environment. Unfortunately, these magic '''alias''' functions do not save in between sessions when defined temporarily, this creates a problem since you would have to create them '''every time''' you start IPython. It will instead display an error message indicating that the alias command does not exist:<source> exit ipython3 vim</source> You should notice an error message indicating invalid syntax. This occurs since you need to create a config file to make this alias persist in-between sessions. You need to exit your ipython session in order to edit this configuration file.<br><br>:#Exit your current IPython session:<source> exit</source>:#Now, create a new ipython alias configuration file and add the following content to it:<source> vim ~/.ipython/profile_default/startup/00-alias.ipy </source>:#Place your newly defined alias inside this file:<source> %alias vim vim</source>:#Save and exit the file. Now let's return to our IPython shell and confirm that our alias is available right away:<source> ipython3 vim</source><br>At this point vim should open successfully and you should now understand how to create new IPython aliases and store them persistently. Use these aliases to customize your environment with any bash commands you thing IPython is missing.<br><br>:# Exit vim and return to the IPython shell. <br><br>
:#Lets setup a directory structures for completing and organizing labs. These should be the locations to store your lab scripts.<source>
mkdir ~/ops435/lab2
:::This resource will appear OVERWHELMING (a huge amount of information)! As we move throughout this course, you will slowly use different magic functions from here, but we will never use all of them. They cover a huge range of different tasks, while we are writing code, allowing us to interactively inspect the Python we are writing and running. Lets move on for now.
<ol><li value="146" style="margin-left:25px;">Issue the following command to exit your ipython session:<source>
exit
</source>