Search

04 April, 2019

How and when to use *args and **kwargs in Python

args and kwargs are special arguments (the words itself are just convention) which can be passed to a function.

13 March, 2019

Python Special Methods : __call__

Python has some methods that are special in a way . If  these methods are created inside a class, they can bring in some unique behaviors . We will talk about the method '__call__' today.

04 March, 2019

21 December, 2018

Python Global Variables

The keyword "global" has a special purpose . If you look into the help docstring of this keyword, you must notice this line :

 It would be impossible to assign to a global variable without "global " 

The word to note is "Assign"

Now . In python , if you declare a variable outside the scope of all functions or classes, it is AVAILABLE GLOBALLY. Meaning I can use it anywhere anytime.

But what is NOT clear , is , you CANNOT change the value\contents of this variable.

Bringing statefulness into your program (e.x an integrating counter ), might need you to keep updating some variable's value . That means, functions must be able to change that value.

Hence, the keyword "global" .

04 December, 2018

Production server launch using Django and Apache and mod wsgi

Some of us develop Django applications which can be used inside Intranet for various purposes.
Some ideas are:
  • HRMS apps
  • Interview Management Tools
  • Grievance Management Tool
  • Financial Report Generators. 

These apps running on intranet, generally don't face too much traffic at a time, but they do need to compute or face heavy queries which is why, it's a good idea to release them on a proper environment . Typically they are light on UI. I choose to use bootstrap which is enough to achieve a decent look . 
Still you should serve them using something which is good at serving static content. So I chose Apache. Lets get started. 

31 October, 2018

Migrating your Django Project database from SQlite3 to MySQL

Django comes with an in-build default setup for SQLLite3 which is good for learning and minor static page based websites. Like blogs which is a standard example . But as soon you decide to create projects that might entail multiple users performing different operations at the same time, SQLLite is not recommended.

Hence the decision to migrate to a better DB system must be as early as possible. I had to under go a similar experience recently . It look a lot of time, trials to finally get it working . I am going to share you the complete steps assuming you don't even have a MySQL setup .

22 October, 2018

Quick guide to Logging to a file using Python

This is for setting up of a file logging system using Logging module


Step 1: Import the logging module.



import logging


Step 2: Create a logger for yourself. 


logger = logging.getLogger(__name__)