Thursday, December 10, 2015

CSV Reading Error (Python)

Just encountered a very ambiguous error in Python while reading a .csv file using the csv library in Python.

The solution made me feel pretty dumb. That is why I am blogging this to remember. From: This is the code snippet I was trying to execute to read csv file at path /home/superuser/Desktop/day.csv.
import csv
with open('./day.csv', 'rb') as csvfile:
  r = csv.reader(csvfile, delimiter=' ', quotechar='|')
  for row in r:
    print ', '.join(row)
Python shell was showing error,
AttributeError: 'module' object has no attribute 'read'
Which made me thing that I'm importing wrong csv library. May be this import csv isn't importing the correct CSV I need. I was correct.
But the solution was pretty awkward. I was saving my file as "" and my program "" itself was importing itself.
Renaming the script to some other name resolved this issue.
Thanks to bernie's answer here:

Thursday, December 3, 2015

Raspbian on Raspberry Pi 2

Following are the steps you need to know before installation of Raspbian - a distribution of Linux for Raspberry Pi 2.
  1. Download image of Raspbian from
  2. Linux
    If you are using Linux/Unix, you need to burn (copy contents from) this image file (.img) into the SD card using following sequence of commands,

    df -h

    To check the list of all the drives mounted into system. Figure out from this list what is the name of your device mounted into /dev/device_name. This device name usually ends with p0, p1 and so on, which indicates the partition indexing. Make sure your card has one partition, at the time of installation and configuration of Raspbian, it automatically partitions into necessary parts.

    Easiest way to figure out what is the newly mounted SD card name in /dev/*, simply df -h before mounting SD card into PC, and then plug and find the newly plugged entry record from df -h output.

    Make sure you unmount the card before burning image into it, by using

    umount /dev/

    Run following command

    sudo dd bs=1M if=[DISK IMAGE NAME] of=[FILESYSTEM]

    Here, in bs=1M means the size of read and write of the bytes at a time equals to 1 mega. Sometimes 1M works while burning the SD card. If this doesn't work for your SD card, try using 4M or some other sector size.
    Wait for a while and your card will be burned with OS.

    Use Win32 Disk Imager software to burn the SD card .img.
  3. Plug SD card into Raspberry Pi and plug it to 5V power, plug LED on HDMI port, keyboard and mouse on USB ports
  4. You will be logged in to Raspbian
    Default username password combination is pi and raspberry respectively
  5. You can expand storage by using raspi-config on terminal after you log in to LDX