Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 PYTHON


  A Python assignment trap

Python has no assignment, it only has reference. Assume, we have following code snippet:>>> values = [0, 1, 2]>>> values[1] = values>>> values[0, [...], 2]Why the result is not [0, [0, 1, 2], 2], instead it goes into an infinite loop? To understand this, we need to understand some basics about Python.Python has no variables, it only has labels. When we run:values = [0, 1, 2]Python will first create a list object [0,1,2], then it labels it as values. If we later run:values = [3, 4, 5]Python will then create a new list object [3,4,5] and it will tear off the values lab...

9,449 0       PYTHON TRAP ASSIGNMENT SHALLOW COPY


  Python Disrupts the Programming Language World- Gets Hot and Popular

Python is one of the fastest growing languages currently. It is undeniable that more and more programmers use Python and deploy it to the best of their use. Everyone, from the freelancer and startups to giant corporations and even governments, is using Python. Let us have a look at the reasons that make it so popular. Training:According to research, 8 out of 10 tech schools in the US teach Python over JAVA. Even the three major MOOC platforms, edX, Coursera, and Udacity have a similar approach and have introductory programmes before anything else and promote it on a massive level. &n...

9,355 1       TEAM DEVELOPMENT PYTHON


  Python: calculate lighter/darker RGB colors

Many times color palettes have lighter and darker variations of the same color. This may be used to convey relative importance, or for something as simple as a gradient. Usually the designer will specify both colors. However, if you have a site that needs to allow user configurable styling, you may not want to ask the user for two variations of the same color.Here is some Python code to take a single color in RGB, and output an artitrarily lighter or darker variation of the same color. You could wrap this in a filter and use it right in your Django templates.view plainprint?def color_vari...

7,830 0       PYTHON RGC COLOR CALUCALTION LIGHTER/DARKER


  Using Fabric to deploy web app

Many people may use FTP and rsync to synchronize codes to server, this way is fine but it may be troublesome when you need to deploy many times a day, actually there is a simple way if you can spend time on finding the fast way. We introduce Fabric today for deploying web app to remote server.Fabric is a deployment tool written with Python, the biggest feature if it is you no need to login to remote server, you can execute remote commands locally.Here is s simple deployment script written with Python : fabfile.py(Do not change the file name). Put it in your project directory.#!/usr/bin/env pyt...

6,752 0       PYTHON SSH FABRIC WEB DEPLOYMENT


  Why Python is important for you

I believe that Python is important for software development. Whilethere are more powerful languages (e.g. Lisp), faster languages(e.g. C), more used languages (e.g. Java), and weirder languages(e.g. Haskell), Python gets a lot of different things right, andright in a combination that no other language I know of has done sofar.It recognises that you’ll spend a lot more time reading code thanwriting it, and focuses on guiding developers to write readablecode. It’s possible to write obfuscated code in Python, but theeasiest way to write the code (assuming you know Python) is almosta...

5,411 0       PYTHON IMPORTANCE PARADIGM


  Currying in Python

What is Currying?Currying is like a kind of incremental binding of function arguments. Let’s define a simple function which takes 5 arguments:1def f(a, b, c, d, e):2    print(a, b, c, d, e)In a language where currying is supported, f is a function which takes one argument (a) and returns a function which takes 4 arguments. This means that f(5) is the following function:1def g(b, c, d, e):2    f(5, b, c, d, e)We could emulate this behavior the following way:1def f(a):2    def g(b, c, d, e):3      &n...

4,294 0       PYTHON IMPLEMENT CURRING BINDING


   Python – parallelizing CPU-bound tasks with multiprocessing

In a previous post on Python threads, I briefly mentioned that threads are unsuitable for CPU-bound tasks, and multiprocessing should be used instead. Here I want to demonstrate this with benchmark numbers, also showing that creating multiple processes in Python is just as simple as creating multiple threads.First, let’s pick a simple computation to use for the benchmarking. I don’t want it to be completely artificial, so I’ll use a dumbed-down version of factorization – breaking a number to its prime factors. Here is a very naive and un-optimized function that take...

3,795 0       PYTHON MULTITASKING MULTIPROCESSING CPU BOUND


  Python Performance Tips, Part 1

To read the Zen of Python, type import this in your Python interpreter. A sharp reader new to Python will notice the word “interpreter”, and realize that Python is another scripting language. “It must be slow!”No question about it: Python program does not run as fast or efficiently as compiled languages. Even Python advocates will tell you performance is the area that Python is not good for. However, YouTube has proven Python is capable of serving 40 million videos per hour. All you have to do is writing efficient code and seek external (C/C++) implementation for speed ...

3,147 1       TIPS PERFORMANCE PYTHON EFFICIENCY