Archive for the ‘Python’ Category

August 15th, 2018

Real Python: The Ultimate Guide to Django Redirects

Comments Off on Real Python: The Ultimate Guide to Django Redirects, Python, by admin.

When you build a Python web application with the Django framework, you’ll at some point have to redirect the user from one URL to another.

In this guide, you’ll learn everything you need to know about HTTP redirects and how to deal with them in Django. At the end of this tutorial, you’ll:

  • Be able to redirect a user from one URL to another URL
  • Know the difference between temporary and permanent redirects
  • Avoid common pitfalls when working with
Read the rest

August 15th, 2018

Import Python: ImportPython – Issue 182

Comments Off on Import Python: ImportPython – Issue 182, Python, by admin.
Worthy
Read

This blog series from Sheroy Marker cover the principles of CD of microservices. Get a practical guide on designing CD workflows for microservices, testing strategies, trunk based development, feature toggles and environment plans.

microservices

,

advert

Several modern programming languages have so-called “null-coalescing” or “null- aware” operators, including C# , Dart, Perl, Swift, and PHP (starting in version 7). These operators provide syntactic sugar

Read the rest

August 14th, 2018

Djangostars: How to build your own blockchain for a financial product

Comments Off on Djangostars: How to build your own blockchain for a financial product, Python, by admin.

How to build your own blockchain for a financial product

Technologies are changing fast; people are not. – Jakob Nielsen

Blockchain is a relatively new technology that many deem is used only for buying Bitcoins. They try to implement it in whatever sphere comes to mind, whether it is fashion, education or healthcare. I would say it is okay — too little time has passed to determine which area of human activity can benefit the most from applying this technology. To understand the practical application of blockchain, we must first … Read the rest

August 14th, 2018

Peter Bengtsson: Django lock decorator with django-redis

Comments Off on Peter Bengtsson: Django lock decorator with django-redis, Python, by admin.

Here’s the code. It’s quick-n-dirty but it works wonderfully:

import functools
import hashlib

from django.core.cache import cache
from django.utils.encoding import force_bytes


def lock_decorator(key_maker=None):
    """
    When you want to lock a function from more than 1 call at a time.
    """

    def decorator(func):
        @functools.wraps(func)
        def inner(*args, **kwargs):
            if key_maker:
                key = key_maker(*args, **kwargs)
            else:
                key =
Read the rest

August 13th, 2018

Peter Bengtsson: django-html-validator now supports Django 2.x

Comments Off on Peter Bengtsson: django-html-validator now supports Django 2.x, Python, by admin.

django-html-validator is a Django project that can validate your generated HTML. It does so by sending the HTML to https://html5.validator.nu/ or you can start your own Java server locally with vnu.jar from here.
The output is that you can have validation errors printed to stdout or you can have them put as .txt files in a temporary directory. You can also include it in your test suite and make it so that tests fail if invalid HTML is generated … Read the rest

August 13th, 2018

Real Python: Advanced Git Tips for Python Developers

Comments Off on Real Python: Advanced Git Tips for Python Developers, Python, by admin.

If you’ve done a little work in Git and are starting to understand the basics we covered in our introduction to Git, but you want to learn to be more efficient and have more control, then this is the place for you!

In this tutorial, we’ll talk about how to address specific commits and entire ranges of commits, using the stash to save temporary work, comparing different commits, changing history, and how to clean up the mess if something … Read the rest

August 11th, 2018

Codementor: Python Environment Management with Conda (Python 2 + 3, Using Multiple Versions of Python)

Comments Off on Codementor: Python Environment Management with Conda (Python 2 + 3, Using Multiple Versions of Python), Python, by admin.

While this section of the post was largely taken and improved from stackoverflow, I feel like it is important to go over how and go over some technical issues people run into. The main idea is to have multiple ipython kernels. The package nbcondakernels will automatically detect different conda environments with notebook kernels and automatically register them.… Read the rest

August 11th, 2018

Weekly Python StackOverflow Report: (cxxxviii) stackoverflow python report

Comments Off on Weekly Python StackOverflow Report: (cxxxviii) stackoverflow python report, Python, by admin.

These are the ten most rated questions at Stack Overflow last week.
Between brackets: [question score / answers count]
Build date: 2018-08-11 16:23:07 GMT


  1. Is there a way to "fork" a list in two based on a condition – [13/6]
  2. What is the difference between "append" and "+" in python? – [8/6]
  3. How do I check the default decimal precision when converting float to str? – [8/3]
  4. Set all values in one column
Read the rest

August 10th, 2018

Peter Bengtsson: Quick dog-piling (aka stampeding herd) URL stresstest

Comments Off on Peter Bengtsson: Quick dog-piling (aka stampeding herd) URL stresstest, Python, by admin.

Whenever you want to quickly bombard a URL with some concurrent traffic, you can use this:

import random
import time
import requests
import concurrent.futures


def _get_size(url):
    sleep = random.random() / 10
    # print("sleep", sleep)
    time.sleep(sleep)
    r = requests.get(url)
    # print(r.status_code)
    assert len(r.text)
    return len(r.text)


def run(url, times=10):
    sizes
Read the rest

August 10th, 2018

Artem Golubin: How Python saves memory when storing strings

Comments Off on Artem Golubin: How Python saves memory when storing strings, Python, by admin.

Since Python 3, the str type uses Unicode representation. Unicode strings can take up to 4 bytes per character depending on the encoding, which sometimes can be expensive from a memory perspective.

To reduce memory consumption and improve performance, Python uses three kinds of internal representations for Unicode strings:

  • 1 byte per char (Latin-1 encoding)
  • 2 bytes per char (UCS-2 encoding)
  • 4 bytes per char (UCS-4 encoding)

When programming in Python all strings behave the same, and most of the … Read the rest