Reading CSV file in python

Python’s official Documentation says below thing about CSV files,

The so-called CSV (Comma Separated Values) format is the most common import and export format for spreadsheets and databases. CSV format was used for many years prior to attempts to describe the format in a standardized way in RFC 4180.

Reading & Writing CSV files is very easy in Python. Below is a code snippet in python which can be used to read q csv file in python.

import csv

with open('filename.csv', 'r') as csv_file:
    reader = csv.reader(csv_file)
    for row in reader:

Django – AttributeError: ‘Http404’ object has no attribute ‘status_code’

If you getting this error, it might be because you are returning Http404 instead of raising it.
you need to raise django.http.Http404, not return it.

example code :

from django.http import Http404

def my_view(request):
        my_object = MyModel.objects.get(pk=1)
    except MyModel.DoesNotExist:
        raise Http404

Python Decorators

Python Conquers The Universe

In August 2009, I wrote a post titled Introduction to Python Decorators. It was an attempt to explain Python decorators in a way that I (and I hoped, others) could grok.

Recently I had occasion to re-read that post. It wasn’t a pleasant experience ? it was pretty clear to me that the attempt had failed.

That failure ? and two other things ? have prompted me to try again.

  • Matt Harrison has published an excellent e-book Guide to: Learning Python Decorators.
  • I now have a theory about why most explanations of decorators (mine included) fail, and some ideas about how better to structure an introduction to decorators.

There is an old saying to the effect that “Every stick has two ends, one by which it may be picked up, and one by which it may not.” I believe that most explanations of decorators fail because they pick…

View original post 1,457 more words