Coding on the Pi

Low cost computing

Coding on the Pi

Python is available on the Raspberry Pi out of the box. An IDE is also provided to help you get up and running Python programs.

The Pi is not limited to Python; it can run any programming language if you have installed the right package. After all, Raspbian, the OS that runs on the Pi is an ARM fork of the Debian Linux.

The Pi has no hard disk; everything runs off an SD card. A 16 GB SD card is bundled with NOOBS installed. The Pi can be set up with the official Raspbian or select an OS from the menu provided. NOOBS, New Out Of The Box Software, is an SD card based installer for the Pi.

I started my Programming career with Java, but my interest in Python became keen after I started dabbling on the Pi. The Pi has everything you need to get started with Python.

Let's say you have installed the Raspbian from the NOOBS installer. When you are done, you will see a start menu. It has several menu items, one of which is Programming. Inside it you will find the IDE's for programming Python.

Let's code a Markdown to HTML converter in Python. I'm writing this post in a Markdown formatted file. I put it in my blog after converting it to HTML using the code below.

You can use one of the bundled python editors or VS Code editor after installing it - my favourite.

import markdown
import os

def convert(infile, outfile):
    markdown.markdownFromFile(input=infile, output=outfile, encoding='utf8')

dir_path = os.getcwd()

md = dir_path + '/convert/md/Welcome to Writer Plus.md'

html = dir_path + '/convert/html/Welcome to Writer Plus.html'

try:
    convert(md, html)
    print('conversion to html completed.')
except ValueError:
    print('conversion failed. Check file path and try again.')

To test this code, you need to have the following directory structure. Save the code as md2html.py as shown below.

md2html
  - convert
    - md
       - test.md
    - html
       - test.html
    - md2html.py

Happy coding!