Changes

Jump to: navigation, search

OPS435 Python Lab 1

544 bytes added, 11:20, 17 May 2017
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, these that theses commands are only here to assist in your python scripting, - we are not 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. These Unfortunately, these magic %'''alias ''' functions do not save in between sessionswhen defined temporarily, this creates a problem since you would have to create them '''every time ''' you start IPython. This It will create a instead display an errormessage indicating that the alias command does not exist:<source> exitipython3 ipython% vim</source> You should be seeing notice an error telling you message indicating invalid syntax. This is happening because we 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 our your newly defined alias insidethis file:<source>% alias vim vim
</source>
:#Save and quit exit the file. Now lets let's return to our IPython shell and confirm that our alias is available right away:<source>ipython3 ipython% 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 now and head back 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.Try using '''TAB''' to help speed up the issuing of the following commands:<source>%mkdir ~/ops435%mkdir ~/ops435/lab1% mkdir ~/ops435/lab2% mkdir ~/ops435/lab3% mkdir ~/ops435/lab4% mkdir ~/ops435/lab5% mkdir ~/ops435/lab6% mkdir ~/ops435/lab7% mkdir ~/ops435/lab8
</source>
:#If you are interested in finding more information about other magic functions in IPython, try entering then within the IPython shell , and typing enter the following:<source>% magic
</source>
: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="13" style="margin-left:::This should show you a OVERWHELMING amount of information, as we move through 25px;">Issue the course we will slowly use different magic functions from here, but we will never use all of them. To be continued. Magic functions than just running bash commands. They cover a huge range of different tasks, while we are writing code, allowing us following command to interactively inspect the Python we are writing and running. Lets move on for now.exit your ipython session:<source> exit</source></li>
<ol><li value="13" style="marginIn the future to see if '''ctrl-left:25px;">d''' works instead of issuing the exit command to quit the ipython shell. Perform the following steps to evaluation evaluate this unit. Running this evaluation script will give you an error, read this error message to see if you can figure out why. This is happening because we are checking a lab script file that we HAVE NOT created yet, so these errors are ok for now. But run these check scripts regularly as you work through the labs, they may give you hints if you get stuck. <presource>
cd ~/ops435/lab1/
pwd #confirm that you are in the right directory
ls CheckLab1.py || wget matrix.senecac.on.ca/~acoatley-willis/CheckLab1.py
python ./CheckLab1.py -f -v lab1a
</presource>
</li>
<li style="margin-left:25px;">Make notes for observations in your lab log book, and proceed to investigation 3.</li></ol>
13,420
edits

Navigation menu