Hi Sharanu,

I will try to answer this as it is an interesting topic.  The “python scripts” 
that you write initially are mostly, single purpose command line ones.
For e.g. in order to add two numbers you can write your script (heck!, let’s 
call it as an worldchangingapp.py) like this.

#worldchangingapp.py

def add(x, y):
    return x + y

if __name__ == ‘__main__’:
   add(4,5)

Simple, isn’t it?

Now, realize that the add() function that you have written may be useful to 
your friend as well, who does not want to reimplement the add function. So you 
decided that you will release your add function as a library, call it as 
arithmeticlib.py  

So arithmeticlib.py has this function now

# arithmeticlib.py

def add(x, y):
    return x + y

And your worldchangingapp can include that lib

# worldchaningapp.py

from arithmeticlib import add

if __name__ == ‘__main__’:
    add(4,5)


Now you are clear what a library is useful for.  

Similar to arithmeticlib, your friends have come out with statisticslib, 
permutationslib, algebraiclib etc to deal with other problems in the domain. 
You realize that you can bundle them all together and ship it as an common 
library called mathslib. To further make it interesting, you decided that you 
will structure your code in such as way, that calling any library will be easy 
and consistent.

For e.g.

doCalculate(x,y) will call arthimeticlib if two numbers are sent.
                           will call statistics lib if two population data is 
sent.
                           will call algebraic lib if two objects which of type 
Algebra are sent.

Your code will look easy to read. The work however, is the way you design your 
library “math lib”.  
At this point, you will design it to make it extensible, so that your user can 
extend the library and add his own functionality too.

Without realizing, you have now created a framework. This is how frameworks are 
usually created.

The hard part is the design process and that is solved by reading about 
software architecture, looking at the examples from the other world (most 
prominently the Java world, where (IMHO) the language leads to designing 
scalable systems in a disciplined manner well) and reading the books on Design 
patterns and looking at the code of popular web frameworks..

So Framework is just a collection of libraries (which is a collection of 
reusable code), which is designed with extensibility and easy of use in mind.

Hope this answers your question and you will be able to crack your interview 
question!. :)

Cheers,
Senthil



--  
Senthil Kumaran
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Sunday, June 1, 2014 at 11:58 PM, Sharanu Patil wrote:

> Hi ,
>  
> I have been working in python in scripting for quiet some time ,
> since i am changing the job, in many interview they are asking below
> quesion
>  
> " have you worked on the python framework ,"
> " what is structure of it ",
> "how do you develop a framework from the scratch "
>  
> It is pleasure to post my first question about python on this mailing
> list
>  
>  
> Thanaks,
> Sharan
> _______________________________________________
> BangPypers mailing list
> BangPypers@python.org (mailto:BangPypers@python.org)
> https://mail.python.org/mailman/listinfo/bangpypers
>  
>  
>  


_______________________________________________
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers

Reply via email to