Tuesday, 29 December 2015

my new start--Django

Django is a framework that uses python
It makes the coding simple.
so easy for developing and deployment

I used the Django documentation
https://docs.djangoproject.com




Many interesting factors are there in this framework. You have to go for many trial and error methods to get expertise with Django also have to keep practicing.If you are known with python you can get easy with the Django.we can import even c ,c++ code into this and no need to code it separately for that.


When you work with Django you can explore many things. Experiment with it,you will enjoy coding.

Django has its ORM(object-relational mapping) and query sets. Django follows MVC pattern,where M - Models,V - Templates and C - Views in the Django framework.Respective terms will follow the functions. i.e Models same model function,Views taken over by the Templates and Controller function is controlled by Views.:)  



Monday, 12 October 2015

GIt-HuB

Github is where people build software.

It is a web based Git repository hosting service.
We can create a repository for us in that with particulars needed for us and can be reffered and used whenever required.
Github is mainly used for source code,other than this it also includes other formats and features.
I have just started using this.
I am getting used to it by listening to many video lectures.

We can familarised with this by practising a lot in our system :) as I am doing it.:)

It will be very usefull and helpfull try for it and enjoy coding.:):)

LIst CompREhenSioN-PYthOn


Python supports a concept called "list comprehensions". It can be used to construct lists in a very natural, easy way, like a mathematician is used to do.
Example to compute prime numbers using list comprehension:
>>> noprimes = [j for i in range(2, 8) for j in range(i*2, 50, i)]
>>> primes = [x for x in range(2, 50) if x not in noprimes]
>>> print primes

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

we can also use nested list comprehension inside of each other.

It will also be usefull along with the map() and lambda() functions.

LAmbdA functions - PYthON

LAMBDA


Python supports a style of programming called functional programming where you can pass functions to other functions to do stuff.Hence lambda functions will be more useful at times.
Lambda is one of the requisites for a readable language.It is the basic form of function definition.

simple example using lambda:
def transform(n):
    return lambda x: x + n
f = transform(3)

f(4) # is 7

Along with this, we use standard functions map(),reduce() and filter()

Example using map():
def fahrenheit(T):
    return ((float(9)/5)*T + 32)
def celsius(T):
    return (float(5)/9)*(T-32)
temp = (36.5, 37, 37.5,39)

F = map(fahrenheit, temp)

C = map(celsius, F)

Example using reduce():
def fahrenheit(T):
    return ((float(9)/5)*T + 32)
def celsius(T):
    return (float(5)/9)*(T-32)
temp = (36.5, 37, 37.5,39)

F = map(fahrenheit, temp)

C = map(celsius, F)

Example using filter():
>>> fib = [0,1,1,2,3,5,8,13,21,34,55]
>>> result = filter(lambda x: x % 2, fib)
>>> print result
[1, 1, 3, 5, 13, 21, 55]
>>> result = filter(lambda x: x % 2 == 0, fib)
>>> print result
[0, 2, 8, 34]

>>> 

DecoraToRS

Python makes creating and using decorators a bit cleaner and nicer for the programmer.
To decorate get_text we don't have to get_text = p_decorator(get_text)
Consider this example:
     a simple way of using decorator with the use of @ symbol to get_text

def p_decorate(func):
   def func_wrapper(name):
       return "<p>{0}</p>".format(func(name))
   return func_wrapper

@p_decorate
def get_text(name):
   return "lorem ipsum, {0} dolor sit amet".format(name)

print get_text("John")

# Outputs <p>lorem ipsum, John dolor sit amet
</p>

A much better approach would be to make our decorator useful for functions and methods alike.

Passing arguments to decorators

consider a example in which 3 decorators are used with same functionalities wrapping up  strings with different tags,we can do better for tat as like follows:

def tags(tag_name):
    def tags_decorator(func):
        def func_wrapper(name):
            return "<{0}>{1}</{0}>".format(tag_name, func(name))
        return func_wrapper
    return tags_decorator

@tags("p")
def get_text(name):
    return "Hello "+name

print get_text("John")

# Outputs <p>Hello John</p>

In this example,above tags is our decorator generator.

Decorators can give so much power and elegance to your program. In general, decorators are ideal for extending the behavior of functions that we don't want to modify. For a great list of useful decorators I suggest you check out the Python Decorator Library


DEscriptORS

Python descriptors are a way to create managed attributes.

Python descriptor protocol is simply a way to specify what happens when an attribute is referenced on a model. It allows a programmer to easily and efficiently manage attribute access:
  • set
  • get
  • delete
Managed attributes are used to protect an attribute from changes or to automatically update the values of a dependant attribute.
We can create a descriptor in a number of ways like:
  • using class methods
  • using property type
  • using property decorators

GeneraTORs-PYthON

Generator is a special kind of iterator.

Any generator also is an iterator not vice versa.
Any generator therefore is a factory that lazily produces values.
Here is an example:fibonacci series using generators
>>> def fib():
...     prev, curr = 0, 1
...     while True:
...         yield curr
...         prev, curr = curr, prev + curr
...
>>> f = fib()
>>> list(islice(f, 0, 10))
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]