Quantcast
Channel: Planet Python
Viewing all 22642 articles
Browse latest View live

Django Weblog: Django bugfix release: 2.1.1

$
0
0

Today we've issued the 2.1.1 bugfix release.

The release package and checksums are available from our downloads page, as well as from the Python Package Index. The PGP key ID used for this release is Carlton Gibson: E17DF5C82B4F9D00.


Talk Python to Me: #175 Teaching Python to network engineers

$
0
0
The discipline of network engineering is quickly moving towards a world where it's as much programming and automation as it is packets and ports. Join me and Hank Preston to discuss what parts of Python are important for network engineers to learn.

Python Bytes: #93 Looking like there will be a PyBlazor!

EuroPython: EuroPython 2018: Videos for Thursday available

$
0
0

We are pleased to announce the second batch of cut videos from EuroPython 2018 in Edinburgh, Scotland, UK.

image

EuroPython 2018 YouTube Playlist

In this batch, we have included all videos for Thursday, July 26 2018, the second conference day.

Next week we will publish videos for the final conference day. In total, we will have more than 130 videos available for you to watch.

All EuroPython videos, including the ones from previous conferences, are available on our EuroPython YouTube Channel.

Enjoy,

EuroPython 2018 Team
https://ep2018.europython.eu/
https://www.europython-society.org/

John Cook: How fast can you multiply matrices?

$
0
0

Suppose you want to multiply two 2 × 2 matrices together. How many multiplication operations does it take? Apparently 8, and yet in 1969 Volker Strassen discovered that he could do it with 7 multiplications.

Upper and lower bounds

The obvious way to multiply two n× n matrices takes n³ operations: each entry in the product is the inner product of a row from the first matrix and a column from the second matrix. That amounts to n² inner products, each requiring n multiplications.

You can multiply two square matrices with O(n³) operations with the method described above, and it must take at least O(n²) operations because the product depends on all of the 2n² entries of the two matrices. Strassen’s result suggests that the optimal algorithm for multiplying matrices takes O(nk) operations for some k between 2 and 3. By applying Strassen’s algorithm recursively to larger matrices you can get k = log2 7 = 2.807.

The best known value at the moment is k = 2.3728639.

Bounds on bounds

Yesterday the blog Gödel’s Lost Letter and P = NP posted an article Limits on Matrix Multiplication where they report on recent developments for finding the smallest value of k. A new paper doesn’t report a new value of k, but a limit on what current approaches to the problem can prove. Maybe k can equal 2, but there is a lower bound, strictly bigger than 2, on how small current approaches can go.

Is this practical?

When I first heard of Strassen’s method, I was told it’s a curious but impractical result. Strassen saved one multiplication at the expense of introducing several more addition operations.

According to the Wikipedia article on matrix multiplication, recursively applying Strassen’s method can save time for n> 100. But there’s more to consider than counting operations. Strassen’s method, and subsequent algorithms, are more complicated. They may not be more efficient in practice even if they use fewer operations because the operations may not vectorize well.

Wikipedia reports that Strassen’s algorithm is not as numerically stable as the traditional approach, but this doesn’t matter when working over finite fields where arithmetic is exact.

Strassen’s method

Let’s look at just what Strassen’s method does. We want to find the product of two matrices:

\begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22}\end{pmatrix} \begin{pmatrix} b_{11} & b_{12} \\ b_{21} & b_{22}\end{pmatrix} = \begin{pmatrix} c_{11} & c_{12} \\ c_{21} & c_{22}\end{pmatrix}

I started to spell out Strassen’s method in LaTeX equations, but I thought it would be much better to write it out in code so I can be sure that I didn’t make a mistake.

The following Python code randomly fills in the values of the a’s and b’s, computes the c’s using the conventional method, then asserts that you can find these values from the q’s computed from Strassen’s method. Note there is one multiplication in each of the seven q’s.

    from random import randint
    
    # Fill matrices with random integer values
    a11 = randint(0, 9)
    a12 = randint(0, 9)
    a21 = randint(0, 9)
    a22 = randint(0, 9)
    b11 = randint(0, 9)
    b12 = randint(0, 9)
    b21 = randint(0, 9)
    b22 = randint(0, 9)
    
    # Traditional matrix multiplication
    c11 = a11*b11 + a12*b21
    c12 = a11*b12 + a12*b22
    c21 = a21*b11 + a22*b21
    c22 = a21*b12 + a22*b22
    
    # Strassen's method
    q1 = (a11 + a22)*(b11 + b22)
    q2 = (a21 + a22)*b11
    q3 = a11*(b12 - b22)
    q4 = a22 * (-b11 + b21)
    q5 = (a11 + a12)*b22
    q6 = (-a11 + a21)*(b11 + b12)
    q7 = (a12 - a22)*(b21 + b22)
    
    assert(c11 == q1 + q4 - q5 + q7)
    assert(c21 == q2 + q4)
    assert(c12 == q3 + q5)
    assert(c22 == q1 + q3 - q2 + q6)

Since Strassen’s method takes more operations than the traditional method for multiplying 2 × 2 matrices, how can it take fewer operations than the traditional method for multiplying large matrices?

When you apply Strassen’s method to a matrix partitioned into submatrices, its multiplications become matrix multiplications, and its additions become matrix additions. These operations are O(n2.807) and O(n2) respectively, so saving multiplications at the cost of more additions is a win.

Related articles

Made With Mu: Making Mu

$
0
0

What does software development look like? Here’s a short video / visualisation of the creation of Mu as told via the interactions, interventions and changes by developers to Mu’s own source code hosted on GitHub.


What exactly are you looking at?

  • The faces represent the developers.
  • The multi-coloured blobs are the source code files that make up Mu.
  • The lines between the source code blobs show how the files are organised together into directories.
  • As time passes, developers can be seen to change, add and delete files as the project matures.

I used the gource tool turn the commit history of Mu’s development on GitHub into a video. I added some Creative Commons licensed music and the results look and sound quite effective. What I really like is how the video reflects the wide variety of people and types of contributions made to the source code for Mu. Together, we’re continuing to build the best editor we possibly can for beginner programmers and those who support them.

Codementor: How to Dockerize a Celery App With Django And RabbitMQ

$
0
0
This post was originally published on Celery. The Missing Blog (https://www.python-celery.com/) on June 12th, 2018. All source code examples used in this blog post can be found on GitHub: ...

Continuum Analytics Blog: Distributed Auto-ML with TPOT with Dask

$
0
0

By Tom Augspurger This work is supported byAnaconda, Inc. This post describes a recent improvement made to TPOT. TPOT is an automated machine learning library for Python. It does some feature engineering and hyper-parameter optimization for you. TPOT uses genetic algorithms to evaluate which models are performing well and how to choose new models to try out in the next …
Read more →

The post Distributed Auto-ML with TPOT with Dask appeared first on Anaconda.


Rene Dudfield: pygame artist in residence grant

$
0
0
An artist residency usually works something like; a person spends some time in either a gallery making something to present or in a music club doing a weekly spot.

Artist in residence.

The first "pygame artist in residence" grant will be for a small amount of money (€512). It is for someone who is already doing stuff with pygame or python in their arts practice. There will be a little thumbnail on the website linking towards an artist statement/patreon page/blog or some such. The residency won't be in a physical space. It lasts for a month, from October 1st - November 1st. At the end of the month the website 'exhibition' will take the form of a small update from the artist — in whatever form that takes.


If you'd like to apply(or nominate someone) please write something short with a link about the arts practice and how python or pygame is used in it.
Email: residency@pygame.org
Applications close: September 15th.
Announced: October 1st.
Amount: €512 paid by paypal.




Why this? Art is awesome.

Ok, there are other reasons... I feel the python world largely ignores the contributions that the game development, graphics, education, music and the arts community provides for python. People who are makers, musicicians, artists, teachers, and game devs have contributed really major things to the python world. And the python website doesn't even mention that art, or games are a thing. They don't exist apparently.
According to python.org art does not exist
From Ada Lovelace the writer(and first programmer), to Steve Jobs who started out at Atari, to Bill gates the author of the first ever PC game, to Konrad Zuse the painter (who happened to also make the first digital computer) — the arts and computers are intertwined. Python itself is named after a comedy group, and was started off within a multimedia group at CWI after the author had worked on a programming system intended for teaching. Would python be the same without import this ( the zen of python) or as fun without import antigravity?

Art, education, music, making, multimedia, and games are important to 'computers' and to python. Sure, stop calling pypi the cheese shop (made by a damn fine baker and game developer) because it's too silly... but please don't erase the arts from existence. The python arts community exists.

Codementor: Will Python Replace Java?

$
0
0
Will Python Replace Java? The reason for Python is becoming more popular and huge surge in number of requirement year on year is Python become a language of choice for all the current trending…

Codementor: Top 25 Python Interview Questions Prepared by Experts

$
0
0
Top 25 Python Interview Questions and Answers Prepared by Experts. Reviews the Python questions and answers and be ready for interviews.Crack the Interview!

Codementor: Can I learn Python in a Month

$
0
0
The question is simple! Can you learn Python coding in a month? Before we get into that we should learn why Python!

Weekly Python StackOverflow Report: (cxli) stackoverflow python report

$
0
0

Real Python: We're Celebrating 1 Million Page Views per Month!

$
0
0

They say people come to Python for the language and stay for the community. We couldn’t agree more! You mean the world to us, and we are honored to have you as a reader!

Today, we’re celebrating reaching 1,000,000 monthly page views at realpython.com.

We are so thankful to you and the rest of the Python community for helping us reach this milestone. More than one million views a month is a mind-blowing number to us—and it means much more to us than the increase in server fees 😉

Reaching this milestone shows us that we are providing you with the resources you need to grow as a developer, and that fills us with joy.

We write comprehensive tutorials twice a week because we care about teaching. We are all passionate Pythonistas, and we want everyone to know that the Python community can be their home, too.

To show our appreciation, we have decided to give away some of our paid Python courses and books as a big thank you to the community for your continued support.

Here’s How It’s Going to Work

The contest will run from September 1st to September 30th. At the end of the contest, a random entrant will be picked to receive the Grand Prize. Each week, throughout the contest, we will randomly pick winners for smaller prizes.

To enter the contest, you can do any of the following:

  • Share the contest
  • Follow us on Twitter
  • Follow us on Facebook
  • Follow us on Instagram
  • Subscribe to our YouTube channel
  • Subscribe to our newsletter

Prizes You Can Win

Now for the part you’ve been waiting for—the prizes!

Here’s what we are giving away each week:

The Grand Prize at the end of the month includes the following:

  • All three Real Python courses (worth $60)
  • Python Tricks eBook + Videos Bundle (worth $29)
  • Managing Python Dependencies Course (worth $49)
  • The Pythonic Wallpapers Pack (worth $9.99)
  • A Real Python mug and shirt from Nerdlettering.com(worth $60)

This adds up to a total value of over $200.

How to Enter the Giveaway Contest

It’s easy! Just click the link below:

Join the Real Python contest for a chance to win »

From all of us at Real Python, thank you! We truly appreciate all the shares, comments, and feedback you have taken the time to provide. It helps us to continually learn as teachers and ensures we are providing the best tutorials and content we can to help you grow as a developer.

Here’s the contest link again:

Enter for your chance to walk away with over $200 of prizes »


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

py.CheckIO: Let the treasure hunt begin!

$
0
0
Escher’s Island

Perhaps you were wondering - why on CheckiO almost all of the missions are scattered and not related in any way? The thing is, we were actually looking for a fascinating story and, finally, we are ready to present it to you. Throughout the entire month of September, on the new Escher’s Island will appear new tasks, which are part of a long story about finding treasures and overcoming difficulties.


Vinay Sajip: Setting up a UK keyboard layout for XRDP on Raspbian Stretch

$
0
0

When I set up xrdp on Raspbian Jessie a while ago, the keyboard layout appeared to be wrong - commonly used keys seemed to be returning US keycodes rather than UK ones. I found this post very helpful in resolving the problem, but it didn't quite fit the bill when I tried to do the same with a Raspbian Stretch instance recently. Here's what I did on Raspbian Stretch to set up xrdp to provide the correct keycodes.

First, I checked the keboard layout was as expected:

$ cat /etc/default/keyboard | grep LAYOUT
XKBLAYOUT="gb"

Then, I generated a keyboard mapping file using xrdp-genkeymap:

$ xrdp-genkeymap km-00000809.ini

This filename follows the current filename convention (under Jessie, it was km-0809.ini). I then copied this file into the xrdp configuration files directory:

$ sudo cp km-00000809.ini /etc/xrdp

The next step was to edit the file /etc/xrdp/xrdp_keyboard.ini, which appears to be new in Raspbian Stretch. Here are the lines I added, in an excerpt from the file:


[default_rdp_layouts]
rdp_layout_us=0x00000409
rdp_layout_de=0x00000407
< ... lines omitted ... >
rdp_layout_br=0x00000416
rdp_layout_pl=0x00000415
rdp_layout_gb=0x00000809

; <rdp layout name> = <X11 keyboard layout value>
[default_layouts_map]
rdp_layout_us=us
rdp_layout_de=de
< ... lines omitted ... >
rdp_layout_br=br(abnt2)
rdp_layout_pl=pl
rdp_layout_gb=gb

In each case, I added the rdp_layout_gb= lines. The final step was to restart the xrdp service:

$ sudo service xrdp restart

On reconnecting, I found that the keycodes were as they should have been, and I had access to the £@'~#\| keys again in their expected places on the keyboard.

DSPIllustrations.com: The Prime Music, Staircase and Riemann Hypothesis

$
0
0

The Prime Numbers' Music, Staircase and Riemann Hypothesis

For DSP, mathematics is a fundamental tool to understand the different techniques. Hence, I'm also interested in different aspects of mathematics. And what aspect could be more "pure" mathematics than number theory and prime numbers? In this regard, to at least understand the still unsolved Riemann Hypothesis, where a price money of 1,000,000 will be given to the one who proves or disproves it, has been bothering me for quite some time. Despite a lot of material about the hypothesis being online, it was the book of Barry Mazur and William Stein entitled "Prime Numbers and the Riemann Hypothesis" which provided me at least a superficial understanding of it.

The nice thing about this book is its very simple approach, requiring not more than high school math. Each page contains graphs and illustrations of the analyzed functions and hence makes it quite easy to follow. Accordingly, it's a very nice book to get to know a bit about the Riemann Hypothesis (RH). However, admittedly, the mathematical treatment is intentionally quite superficial.

In this notebook, I do not want to directly talk about the RH. Instead, the notebook arose when I tried to replicate some calculations from the ...

PyBites: PyBites Twitter Digest - Issue 28, 2018

$
0
0

How to find stuff in Git

Submitted by @clamytoe.

Exposed user TLS Certificate Private Keys... not good!

Submitted by @dgjustice.

Documentation is so important. This is a great idea!

Had no idea the PSF had a job board! Check it out!

Another quality RealPy article: Advanced Git Tips for Python Devs

Nice! An A-Z of useful Python tricks

Submitted by @Erik.

No reason why you shouldn't be a member of the PSF! Get on it!

Such a wonderful initiative to support young women with coding!

Asycnio socket tutorial

Learning Python: From Zero to Hero. A great intro!

Super interesting episode of the Talk Python Podcast! A definite trend in network engineering these days

An awesome deep learning demo!

Agreed! Have to put yourself out there no matter what. That's how PyBites started!

What a project! Run Python in your browser!

Ha!


>>>frompybitesimportBob,JulianKeepCalmandCodeinPython!

Test and Code: 46: Testing Hard To Test Applications - Anthony Shaw

$
0
0

How do you write tests for things that aren’t that easy to write tests for?

That question is a possibly terrible summary of a question sent to me by a listener. And to help me start answering that question, I asked a friend of mine to help, Antony Shaw.

Of course, different types of applications have different test strategies, so there’s not a universal answer. But I know some of you out there have experience and expertise around how to tackle this problem.

Listen to the discussion Anthony and I have about it, and let me know if you have some techniques or tips to add.

Special Guest: Anthony Shaw.

Sponsored By:

Support Test and Code

<p>How do you write tests for things that aren’t that easy to write tests for?</p> <p>That question is a possibly terrible summary of a question sent to me by a listener. And to help me start answering that question, I asked a friend of mine to help, Antony Shaw.</p> <p>Of course, different types of applications have different test strategies, so there’s not a universal answer. But I know some of you out there have experience and expertise around how to tackle this problem.</p> <p>Listen to the discussion Anthony and I have about it, and let me know if you have some techniques or tips to add. </p><p>Special Guest: Anthony Shaw.</p><p>Sponsored By:</p><ul><li><a rel="nofollow" href="https://www.patreon.com/testpodcast">Patreon Supporters</a>: <a rel="nofollow" href="https://www.patreon.com/testpodcast">Help support the show with as little as $1 per month. Funds help pay for expenses associated with the show.</a></li></ul><p><a rel="payment" href="https://www.patreon.com/testpodcast">Support Test and Code</a></p>

Techiediaries - Django: React Basics Tutorial for Django Developers [2018]

$
0
0

In this tutorial, We'll introduce React basics to Django developers. You can use React to build UIs using re-usable components which allow maximum reusability and a virtual DOM that provides better performance.

In this tutorial, we'll learn how to include React in a Django template and learn about the basics of React such as components, state and props.

But what's virtual DOM? This is the definition from the official React website

The virtual DOM (VDOM) is a programming concept where an ideal, or “virtual”, representation of a UI is kept in memory and synced with the “real” DOM by a library such as ReactDOM. This process is called reconciliation.

React is nowadays-2018-the most popular front-end library for building User Interfaces. Throughout this tutorial we'll go through a basic understanding of React.js by creating a React application from scratch and step by step. We will focus on the core features of React. After getting the core concepts, you can dive into more learning more comfortably.

By following this tutorial, you'll learn:

  • How to get started with React using a <script> tag;

  • How to include React in a Django template;

  • What's a React component;

  • How to create React components;

  • How to use the ReactDOM library to mount your React app into the DOM;

  • How to handle data in React;

  • The difference between props and state in React;

  • How to use props;

  • How to use state;

  • How to mutate or update state in React etc.

React provides a set of modern features such as:

  • A component based architecture;

  • Reusable components;

  • Stateful and stateless components;

  • And virtual dom.

Getting Started with React

Since we are getting started with React, we are not going to use complicated tools such as create-react-app (In fact this tool was created to make creating React applications less complex without worrying about Webpack and complex front-end tooling), instead we'll use a simple setup i.e the old way of using libraries in front-end web development.

Start by creating a basic HTML page:

<html><head><title>React Tutorial</title></head><body></body></html>

Now use the <script> tag to include React and ReactDOM libraries. In the <head> of your HTML page, add:

<script  src="https://unpkg.com/react@15/dist/react.min.js"></script><script  src="https://unpkg.com/react-dom@15/dist/react-dom.min.js"></script>

You also need to include Babel:

<script  src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>

We are using the unpkg.com service which allows us to import NPM modules as normal JavaScript scripts without using npm and related modern front-end tools to install and use the dependencies.

Since React makes use of modern JavaScript features, we use Babel which is transpiler that transpiles the ES6 features to JavaScript features that can be interprited by most existing browsers.

We also use Babel for transforming JSX templates (used by React to include HTML in JavaScript) into JavaScript.

We are loading React from a <script> tag, you can also use modern tools like npm and the import/require system when building complex apps.

Next, we need to add a root <div> where we'll mount our React application.

Inside the <body> element, add the following HTML:

<divid="root"></div>

Also, inside the <body> tag, add the following <script> where we're going to add the React code:

<scripttype="text/babel">/* React code */</script>

At this step, you can install an http server so you can run the example on your browser or simply use codepen.

Including React in Django Templates

In this section, we'll see how to include React in Django templates. Django has a powerful template system that makes use of inheritance to reduce repetition and augment code reuse so let's start by creating the base.html template inside the templates folder and add the following HTML:


{% load static %}

<!doctype html><html><head><metacharset="utf-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><title>Django & React Tutorial</title><metacontent="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"name="viewport"></head><script  src="https://unpkg.com/react@15/dist/react.min.js"></script><script  src="https://unpkg.com/react-dom@15/dist/react-dom.min.js"></script><script  src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script><body><noscript>You need to enable JavaScript to continue with this application.</noscript><divid="root"></div>

{% block inner %}

{% endblock %}

</body></html>

Create an index.html template that extends the base.html template and add the following content:


{% extends "base.html" %}



{% block inner %}

<script  type="text/babel">/* React code here */</script>

{% endblock %}

React Components

In React, you build your UI as a hierarchy of components. A component controls a part of the UI and It's simply a JavaScript/ES6 class that extends the base React.Component. For example, this is a simple HelloWorld component:

classHelloWorldextendsReact.Component{render(){return<h1>HelloWorld!</h1>;
}}

The component simply renders a <h1>Hello World!</h1>. We use the render() method which is provided by the parent React.Component. The render() method should return what your component needs to render on the screen.

In React, you can use different types of components such as parent and child components. You will also make use of smart and dump components. A smart component maintains state while a dump component doesn't maintain any state.

Components have many benefits. The most important benefit for a developer is code-reuse i.e you can reuse your components in the same app or throughout multiple apps.

Using ReactDOM

Now that we have a basic React component that renders something on the screen and a simple HTML page, we need to mount the simple React application in the HTML body of our page. For this matter, we need to use the ReactDOM library.

Before the closing </body> tag, add the following code within a <script> tag:

<script>ReactDOM.render(<HelloWorld/>,document.getElementById("root"));</script>

We use the render() method to mount the our top-level and only component into the root <div> which we grab using the document.getElementById("root") method.

This will be enough to mount our React component. You should now see a Hello World on the screen.

Handling Data in React

You can make use of data in React using two forms: props and state.

Props are used to communicate or pass data between components and they are external to the component while state is used to maintain the internal state of a component.

A React component can change its internal state directly but not the props.

Understanding React Props

Props allow you to pass data to a component which allows for maximum re-usability of the component.

Let's, for example change our previous HelloWorld component to be more dynamic by rendering a message that's passed via a prop instead of always rendering Hello World.

We can pass a message prop to the component using the following syntax:

<HelloWorldmessage="Hello React"/>

The prop is called message, you can use any meaningful name for your prop. The message prop takes a Hello React value.

Now, we need to change the component to handle the prop:

classHelloWorldextendsReact.Component{render(){return<h1>{this.props.message}</h1>;
}}

We access the props in our component by using the this.props object. Since this is JavaScript code we include it inside curly braces which tells JSX to interpret and render the result.

As you can see this allows us to use the component to render different messages instead of just the Hello World message.

Understanding React State

A component in React can maintain its own internal state using a state object. The component that maintains a state is called a smart component.

Let's now add state to our previous component:

classHelloWorldextendsReact.Component{constructor(){super();this.state={message:"Hello React!"};}render(){return<p>{this.state.message}</p>;
}}

In the constructor of the component, we simply assign a JavaScript object to this.state to initialize it.

The message is now a part of the internal state of the component.

We can access the state using this.state.

Mutating/Changing State in React

To mutate or change state in your React component, you simply need to use the this.setState() method. For example:

this.setState({message:"Hello Again"});

Conclusion

In this tutorial, we've quickly gone through the basic concepts of React.

Viewing all 22642 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>