Sunday, 11 August 2013

List Comprehension in Python

Sunday, 16 June 2013

Installing PIP in Windows

This is one of the toughest things I have come across recently. Installing PIP on linux is altogether different thing. But I really had a hard time while installing PIP on windows. There are so many suggestion available on the internet that hardly worked for me. But the solution I found out is worth sharing.

What is PIP?

--> PIP is a package management system  which is used to install python software packages directly from your command line.

Steps to install PIP :
Download pip windows installer from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip.
Download the ez_setup.py script and run it by downloading from  https://pypi.python.org/pypi/setuptools/0.7.2#windows
Run the script.
Once installation is complete, you will find an easy_install .exe program in your Python/scripts subdirectory.
Run the pip installer.
Add C:\Python27\Scripts to you path and you are good to go.

Wednesday, 23 January 2013

PASS BY VALUE OR PASS BY REFERENCE IN JAVA:


Java doesn't pass method arguments by reference; it passes them by value.

public void testSwap( Sample s1, Sample s2){
  
           s1.x = 100;
           s1.y = 100;
           Sample temp = s1;
           s1 = s2;
          s2 = temp;
}


public static void main(String [] args)
{
  Sample s1 = new Sample(0,0);
  Sample s2 = new Sample(0,0);
  ("X: " + s1.x + " Y: " +s1.y);
  System.out.println("X: " + s2.x + " Y: " +s2.y);
  System.out.println(" ");
  testSwap (s1 ,s1);
  System.out.println("X: " + s1.x + " Y:" + s1.y);
  System.out.println("X: " + s2.x + " Y: " +s2.y);
}

The method successfully alters the value of s1, even though it is passed by value; however, a swap of s1 and s2 fails! This is the major source of confusion. In the main() method, s1 and s2 are nothing more than object references. When we pass s1 and s22 to the testSwap() method, Java passes the references by value just like any other parameter. This means the references passed to the method are actually copies of the original references.


Only the method references are swapped, not the original ones.