Day 01-05 – Getting Started with Python

Day 01-05 – Getting Started with Python

Welcome, today I begin my first ever #100daysofcode project.

Hi, you are reading a post in my #100daysofcode Python Edition blog series. I’m glad you are here and I hope you find something useful!

DigitalOcean offers one-click deployment of popular applications such as WordPress, Django, MongoDB, Docker, and even preconfigured Kubernetes Clusters. Deploy your next app in seconds. Get $100 in cloud credits from DigitalOcean

Ad Notice I will receive a small commission that helps support this blog at no cost to you.

Day 1 Thursday, January 3rd 2019

A little about me. I have worked in software development at various times in my career but in my current role I do not write code daily or even weekly. I do not consider myself a coding master nor a novice, but I’m always pushing myself to improve through continuous learning. When I first learned about the #100daysofcode challenge, I knew I wanted to participate! Well that’s about enough rambling from me, the rest of these pages will be dedicated to python code!

My language of choice for this challenge is Python! It’s very enjoyable to work with, has a rich ecosystem of modules, and has become an extremely popular programming language.

To start with here on Day #1 I’m going to install miniconda which will give me python+jupyter notebook+numpy+pandas+matplotlib.

Getting jupyter notebook up and running on Windows

  1. Download and install miniconda from https://conda.io/miniconda.html
  2. Launch Anaconda Prompt in privileged mode (right-click|run as administrator)
  3. Run conda list to see what conda packages we get preinstalled.
  4. Lets install jupyter and our other packages
    conda install jupyter numpy pandas matplotlib -y
  5. Now, check for updates on all of our conda packages
    conda update --all -y
  6. Finally, click Start and launch Jupyter Notebook

If you are following along you should now see a webpage that looks like this…

jupyter-notebook-miniconda
Welcome to Jupyter Notebooks!

If you notice in the screenshot above my jupyter notebook has me starting out with a root filesystem of C:\users\jcutrer\. You can launch jupyter notebook from within any directory and it will become the root of the filesystem displayed. I hope that makes sense, if not leave a comment below 🧐.

Launch jupyter from the command line

jupyter notebook

All of the python code that I write for this challenge will be published in my github repository joncutrer/100DaysofCode2019. I will be checking in to github using Github Desktop for Windows which you can download here

01 Python Basics Revised.ipynb

Day 1 Summary

  • Setup miniconda and jupyter notebook environment
  • Python Basics Revisited Notebook
  • TODO Find a good solution to embed the python notebook inline As you can see above I figured out a way to embed the notebook in this blog post.

Day 2 Friday, January 4th 2019

Wow! Today was a busy day but I still managed to complete my 1 hour of coding. I haven’t mentioned it yet but I am also working through this this python course on Udemy. I’ve completed Section 1-3.

Day 2 notebook focuses on strings in python and explores some of the methods available on the str class.

02 Python String Methods.ipynb

Day 2 Summary

  • No progress 😒 on embedding jupyter notebooks here on the blog post. Yay! Embedded notebooks work. 😁 Read Day 3 to see how I did it.
  • Python String Methods Notebook
  • Completed sections 1-3 of Python Course

Day 3 Saturday, January 5th 2019

Day 3 is a little different from my intended flow of one notebook per day. Today I set out to solve how I was going to embed the daily notebooks directly on the page.

Going into this challenge I knew that I could export IPython notebooks using the nbconvert tool. Then I assumed someone has surely already solved this problem in the form of a WordPress plugin. It turns out there is no ready-to-go WordPress plugin for embedding IPython notebooks ☹.

Next, I thought, “That’s OK, I’ll just embed the exported html files on the page using iframes”. This is exactly what I ended up doing but there is one big problem with this approach. When nbconvert exports it embeds all required css as inline css. This includes bootstrap.min.css and font-awesome resulting in exported html files being over 400K.

Here’s what I did to solve this problem. I ended up creating a custom template for nbconvert that omits the inline css and links to the css file instead. Next, I create a small batch file that automates the process of exporting all the notebooks with one command.

It may not give you the full context but here’s the script.

export-notebooks.bat

Day 3 Summary

  • Added a references section at the bottom of each posts with useful links.
  • Solved the problem of exporting and embedding IPython Notebooks into WordPress
  • Created a custom nbconvert export (jinja) template that does not inline css.
  • Created a batch script to automate notebook exports
  • No Day 3 Notebook 😲 but you can find the batch script and nocss template here

Day 4 Sunday, January 6th 2019

I’m back again for Day 4 of the #100daysofcode challenge! Today’s time was spent working with python lists. The notebook covers a lot of concepts about Python Lists.

Day 4 Summary


Here is a coding tip to end Day 4!


Day 5 Monday, January 7th 2019

Welcome back, Day 5 starts out with a new enhancement I’ve added here on the blog posts. You can now click the “Run this Notebook” link at the top of each embedded notebook and run it yourself on mybinder.org. I think that is just too cool!

Run notebook link

“I have a dilemma”

When I began this #100daysofcode challenge I imagined having one notebook per day. This became a problem yesterday when I covered python lists. Python lists simply cannot be explored or covered in one hour. So starting today, I’m restructuring my github repo and the notebooks are no longer named Day 01, Day 02, etc.

I think this simpler approach of one notebook per topic will serve me and you the reader better going forward.

Day 5 Summary

  • Added Run this notebook links to each embedded notebook.
  • Went back and relinked all the notebooks after reorganizing the github repo.
  • Finished out the Python Lists notebook

03 Python Data Structures Part 1 Lists.ipynb


References

Amazon AWS too complex and expensive? You will love the simplicity of DigitalOcean. Deploy your next app in seconds. Get $100 in cloud credits from DigitalOcean

Ad Notice I will receive a small commission that helps support this blog at no cost to you.

Thanks for following along, feel free to comment below and continue reading my 2019 #100daysofcode project posts.


One Reply to “Day 01-05 – Getting Started with Python”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.