## Ship It Day Q1 2017

Jan 18 2017 □ [Archived Version] □ Published at Caktus Blog

Jan 18 2017 □ [Archived Version] □ Published at Caktus Blog

Last Friday, Caktus set aside client projects for our regular quarterly ShipIt Day. From gerrymandered districts to RPython and meetup planning, the team started off 2017 with another great ShipIt. Books for the Caktus Library Liza uses Delicious Library to track books in the Caktus Library. However, the tracking of books isn't visible to the...

Jan 18 2017 □ [Archived Version] □ Published at GoDjango Screencasts and Tutorials

There are **a lot of ways to deploy Django** so I think it is one of those topics people are really curious about how other people do it. Generally, in all deploys you need to **get the latest code, run migrations, collect your static files** and **restart web server processes**. How yo do those steps, that is the interesting part.

In todays video I go over How I deploy Django day to day, followed by some other ways I have done it. This is definitely a topic you can make as easy or complicated as you want.

Here is the link again: https://www.youtube.com/watch?v=43lIXCPMw_8?vq=hd720

Jan 18 2017 □ [Archived Version] □ Published at The Django weblog

Django 1.11 alpha 1 is now available. It represents the first stage in the 1.11 release cycle and is an opportunity for you to try out the changes coming in Django 1.11.

Django 1.11 has a medley of new features which you can read about in the in-development 1.11 release notes.

This alpha milestone marks a complete feature freeze. The current release schedule calls for a beta release in about a month and a release candidate about a month from then. We'll only be able to keep this schedule if we get early and often testing from the community. Updates on the release schedule schedule are available on the django-developers mailing list.

As with all alpha and beta packages, this is **not** for production use. But
if you'd like to take some of the new features for a spin, or to help find and
fix bugs (which should be reported to the issue tracker), you can grab a
copy of the alpha package from our downloads page or on PyPI.

The PGP key ID used for this release is Tim Graham: 1E8ABDC773EDE252.

Jan 16 2017 □ [Archived Version] □ Published at tuts+

Even the most basic mathematical operations can sometimes give an erroneous result. This happens due to limitations in storing the exact value of some numbers. You can overcome these limitations by using the decimal module in Python. Similarly, neither the *math* nor the *cmath* module that we learned about in our last tutorial can help us in doing fraction-based arithmetic. However, the fractions module in Python does exactly that.

In this tutorial, you will learn about both these modules and the different functions they make available.

You are probably wondering why we need a module to do basic arithmetic with decimal numbers when we can already do the same using floats.

Before I answer this question, I want you to take a guess about the output value if you type `0.1 + 0.2`

in the Python console. If you guessed that the output should be 0.3, you will be surprised when you check out the actual result, which is 0.30000000000000004. You can try some other calculation like `0.05 + 0.1`

and you will get 0.15000000000000002.

To understand what's going on here, try to represent `1/3`

in decimal form, and you will notice that the number is actually non-terminating in base 10. Similarly, some numbers like 0.1 or 1/10 are non-terminating in base 2. Since these numbers still need to be represented somehow, a few approximations are made while storing them, which results in those errors.

The number 0.30000000000000004 is actually very close to 0.3, so we can get away with this approximation most of the time. Unfortunately, this approximation is not going to cut it when you are simulating a satellite launch or dealing with money. Another problem with these approximations is that the errors keep piling up.

To get precise results like the ones we are used to dealing with when doing calculations by hand, we need something that supports fast, correctly rounded, decimal floating point arithmetic, and the *decimal* module does exactly that.

Before using the module, you need to import it first. After that, you can create decimals from integers, strings, floats, or tuples. When the decimal is constructed from an integer or a float, there is an exact conversion of the value of that number. Take a look at the examples below to see what I mean:

from decimal import Decimal Decimal(121) # returns Decimal('121') Decimal(0.05) # returns Decimal('0.05000000000000000277555756') Decimal('0.05') # returns Decimal('0.05') Decimal((0, (8, 3, 2, 4), -3)) # returns Decimal('8.324') Decimal((1, (8, 3, 2, 4), -1)) # returns Decimal('-832.4')

As you can see, the value of `Decimal(0.05)`

is slightly different from `Decimal('0.05')`

. This means that when you add 0.05 and 0.1, you should use `decimal.Decimal('0.05')`

and `decimal.Decimal('0.1')`

to construct the decimals.

from decimal import Decimal Decimal('0.05') + Decimal('0.1') # returns Decimal('0.15') Decimal(0.05) + Decimal(0.1) # returns Decimal('0.1500000000000000083266726847')

Now that you can perform various operations on decimals, you might want to control the precision or rounding for those operations. This can be done by using the `getcontext()`

function. This function allows you to get as well as set the value of the precision and rounding options, among other things.

Please keep in mind that both rounding and precision come into play only during arithmetic operations and not while you are creating the decimals themselves.

import decimal from decimal import Decimal, getcontext Decimal(1) / Decimal(13) # returns Decimal('0.07692307692307692307692307692') getcontext().prec = 10 Decimal(0.03) # returns Decimal('0.02999999999999999888977697537') Decimal(1) / Decimal(7) # returns Decimal('0.1428571429') getcontext().rounding = decimal.ROUND_DOWN Decimal(1) / Decimal(7) # returns Decimal('0.1428571428')

You can also use some of the mathematical functions like `sqrt()`

, `exp()`

, and `log()`

with decimals. Here are a few examples:

import decimal from decimal import Decimal, getcontext Decimal(2).sqrt() # returns Decimal('1.414213562373095048801688724') getcontext().prec = 4 Decimal('2').sqrt() # returns Decimal('1.414') Decimal('2000').log10() # returns Decimal('3.301')

Sometimes, you might face situations where you need to perform various operations on fractions or the final result needs to be a fraction. The fractions module can be of great help in these cases. It allows you to create a `Fraction`

instance from numbers, floats, decimals, and even strings. Just like the decimal module, there are a few issues with this module as well when it comes to creating fractions from floats. Here are a few examples:

from fractions import Fraction from decimal import Decimal Fraction(11, 35) # returns Fraction(11, 35) Fraction(10, 18) # returns Fraction(5, 9) Fraction('8/25') # returns Fraction(8, 25) Fraction(1.13) # returns Fraction(1272266894732165, 1125899906842624) Fraction('1.13') # returns Fraction(113, 100) Fraction(Decimal('1.13')) # returns Fraction(113, 100)

You can also perform simple mathematical operations like addition and subtraction on fractions just like regular numbers.

from fractions import Fraction Fraction(113, 100) + Fraction(25, 18) # returns Fraction(2267, 900) Fraction(18, 5) / Fraction(18, 10) # returns Fraction(2, 1) Fraction(18, 5) * Fraction(16, 19) # returns Fraction(288, 95) Fraction(18, 5) * Fraction(15, 36) # returns Fraction(3, 2) Fraction(12, 5) ** Fraction(12, 10) # returns 2.8592589556010197

The module also has a few important methods like `limit_denominator(max_denominator)`

which will find and return a fraction closest in value to the given fraction whose denominator is at most `max_denominator`

. You can also return the numerator of a given fraction in the lowest term by using the `numerator`

property and the denominator by using the `denominator`

property.

from fractions import Fraction Fraction('3.14159265358979323846') # returns Fraction(157079632679489661923, 50000000000000000000) Fraction('3.14159265358979323846').limit_denominator(10000) # returns Fraction(355, 113) Fraction('3.14159265358979323846').limit_denominator(100) # returns Fraction(311, 99) Fraction('3.14159265358979323846').limit_denominator(10) # returns Fraction(22, 7) Fraction(125, 50).numerator # returns 5 Fraction(125, 50).denominator # returns 2

You can also use this module with various functions in the *math* module to perform fraction-based calculations.

import math from fractions import Fraction math.sqrt(Fraction(25, 4)) # returns 2.5 math.sqrt(Fraction(28,3)) # returns 3.0550504633038935 math.floor(Fraction(3558, 1213)) # returns 2 Fraction(math.sin(math.pi/3)) # returns Fraction(3900231685776981, 4503599627370496) Fraction(math.sin(math.pi/3)).limit_denominator(10) # returns Fraction(6, 7)

These two modules should be sufficient to help you perform common operations on both decimals and fractions. As shown in the last section, you can use these modules along with the math module to calculate the value of all kinds of mathematical functions in the format you desire.

In the next tutorial of the series, you will learn about the *random* module in Python.

Jan 16 2017 □ [Archived Version] □ Published at eGenix.com News & Events

The following text is in German, since we're announcing a regional user group meeting in Düsseldorf, Germany.

Das nächste Python Meeting Düsseldorf findet an folgendem Termin statt:

18.01.2017, 18:00 Uhr

Raum 1, 2.OG im Bürgerhaus Stadtteilzentrum Bilk

Düsseldorfer Arcaden, Bachstr. 145, 40217 Düsseldorf

Charlie Clark

"Kurze Einführung in openpyxl und Pandas"

Jochen Wersdörfer

"CookieCutter"

Marc-Andre Lemburg

"Optimierung in Python mit PuLP"

Wir treffen uns um 18:00 Uhr im Bürgerhaus in den Düsseldorfer Arcaden.

Das Bürgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet
sich an der Seite der Tiefgarageneinfahrt der Düsseldorfer Arcaden.

Über dem Eingang steht ein großes "Schwimm’ in Bilk" Logo. Hinter der Tür
direkt links zu den zwei Aufzügen, dann in den 2. Stock hochfahren. Der
Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt.

>>> Eingang in Google Street View

Das Python Meeting Düsseldorf ist eine regelmäßige Veranstaltung in Düsseldorf, die sich an Python Begeisterte aus der Region wendet.

Einen guten Überblick über die Vorträge bietet unser PyDDF YouTube-Kanal, auf dem wir Videos der Vorträge nach den Meetings veröffentlichen.Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, Düsseldorf:

Das Python Meeting Düsseldorf nutzt eine Mischung aus (Lightning) Talks und offener Diskussion.

Vorträge können vorher angemeldet werden, oder auch spontan während des Treffens eingebracht werden. Ein Beamer mit XGA Auflösung steht zur Verfügung.(Lightning) Talk Anmeldung bitte formlos per EMail an [email protected]

Das Python Meeting Düsseldorf wird von Python Nutzern für Python Nutzer veranstaltet.

Da Tagungsraum, Beamer, Internet und Getränke Kosten produzieren, bitten wir die Teilnehmer um einen Beitrag in Höhe von EUR 10,00 inkl. 19% Mwst. Schüler und Studenten zahlen EUR 5,00 inkl. 19% Mwst.

Wir möchten alle Teilnehmer bitten, den Betrag in bar mitzubringen.

Da wir nur für ca. 20 Personen Sitzplätze haben, möchten wir bitten,
sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen.
Es erleichtert uns allerdings die Planung.

**Meeting Anmeldung** bitte formlos per EMail an [email protected]

Weitere Informationen finden Sie auf der Webseite des Meetings:

http://pyddf.de/

Viel Spaß !

Marc-Andre Lemburg, eGenix.com

Jan 13 2017 □ [Archived Version] □ Published at Dougal Matthews under tags flask frozen python static

I was investigating static site generators last week, I have used a couple of
them before; this website is generated by Pelican, I am one of the
maintainers of MkDocs, I use Sphinx regularly and I have written my own
before^{1}.

However, this time I wanted something a little …

Jan 12 2017 □ [Archived Version] □ Published at tuts+

Do you want to learn more about developing iOS apps with Swift? How about building web applications with Go, or functional programming in JavaScript? Our latest batch of eBooks will teach you all you need to know about these topics and more.

In the past couple of months we’ve made 16 new eBooks available for Envato Tuts+ subscribers to download. Here’s a selection of those eBooks and a summary of what you can learn from them.

In programming, there are several problems that occur frequently. To solve these problems, there are various repeatable solutions that are known as design patterns. Design patterns are a great way to improve the efficiency of your programs and improve your productivity.

This book is a collection of the most important patterns you need to improve your applications’ performance and your productivity. The journey starts by explaining the current challenges when designing and developing an application and how you can solve these challenges by applying the correct design pattern and best practices.

The Swift: Developing iOS Applications eBook will take you on a journey to become an efficient iOS and macOS developer, with the latest trending topic in town. Right from the basics to the advanced level topics, this eBook will cover everything in detail.

The learning path consists of four modules. Each of these modules is a mini-book in its own right, and as you complete each one, you’ll gain key skills and be ready for the material in the next module.

Python is a dynamic and powerful programming language, having its application in a wide range of domains. It has an easy-to-use, simple syntax, and a powerful library, which includes hundreds of modules to provide routines for a wide range of applications, thus making it a popular language among programming enthusiasts.

This eBook will take you on a journey from basic programming practices to high-end tools and techniques that will give you an edge over your peers.

There’s a new choice for implementing APIs: the open-source and Facebook-created GraphQL specification. Designed to solve many of the issues of working with REST, GraphQL comes alongside RelayJS, a React library for querying a server that implements the GraphQL specification. This book takes you quickly and simply through the skills you need to be able to build production-ready applications with both GraphQL and RelayJS.

Functional programming is a way of writing cleaner code through clever ways of mutating, combining, and using functions. And JavaScript provides an excellent medium for this approach. By learning how to expose JavaScript's true identity as a functional language, we can implement web apps that are more powerful, easier to maintain and more reliable.

This book will take you on a journey to show you how functional programming when combined with other techniques makes JavaScript programming more efficient.

Ionic 2, the latest version of Ionic Mobile SDK, is built on the top of latest technologies such as Angular 2, TypeScript, SASS, and lot more. The idea behind Ionic 2 is to make the entire app development process even more fun.

This book makes it possible to build fun and engaging apps using Ionic 2. You will learn how to use various Ionic components, integrate external services, derive capabilities, and most importantly how to make professional apps with Ionic 2.

By the end of this book, you will be able to proudly call yourself a pro Ionic developer who can create a host of different apps with Ionic, and you’ll have a deeper practical understanding of Ionic.

Go is an open-source programming language that makes it easy to build simple, reliable, and efficient software. It is a statically typed language with syntax loosely derived from that of C, adding garbage collection, type safety, some dynamic-typing capabilities, additional built-in types such as variable-length arrays and key-value maps, and a large standard library.

This eBook starts with a walkthrough of the topics most critical to anyone building a new web application. Whether it’s keeping your application secure, connecting to your database, enabling token-based authentication, or utilizing logic-less templates, this book has you covered.

Data science is hot right now, and the need for multitalented developers is greater than ever before. A basic grounding in building apps with a framework as minimalistic, powerful, and easy-to-learn as Django will be a useful skill to launch your career as an entrepreneur or web developer.

Django is a web framework that was designed to strike a balance between rapid web development and high performance. This book will take you on a journey to become an efficient web developer thoroughly understanding the key concepts of Django framework. By the end of the four modules, you will be able to leverage the Django framework to develop a fully functional web application with minimal effort.

Subscribe to Envato Tuts+ for access to our library of hundreds of eBooks. With a Yearly subscription, you can download up to five eBooks per month, while the Yearly Pro subscription gives you unlimited access.

Jan 12 2017 □ [Archived Version] □ Published at Nerdy Dork under tags programming & internet

I love the idea of Disney Circle, Torch, and Luma where you can get on your phone and pause the internet for certain devices at home. But Circle being the cheapest, I didn’t really want to shell out $99 for yet another device when I just paid $155 for a new Nighthawk R7000 router and […]

The post Internet Pause Button with DD-WRT appeared first on Dustin Davis.

Jan 12 2017 □ [Archived Version] □ Published at Djangojobs.Net latest jobs

- Django templating using HTML5, CSS3, Bootstrap for modern browsers
- version control using git (flow)
- Good responsive design knowledge and accessibility skills (WCAG/WAI exposure)
- Javascript (DOM manipulation without sole relienced upon jQuery)
- node.js / bower / gulp knowledge
- LESS (or SASS) experience
- I18n L10n, G11n exposure
- comfortable using a Linux/Mac OS CLI

- Agile development experience
- Jira
- Slack
- CI/CD

- US or naturalized citizen - no H-1B
*** Must be able to work comfortably and reliably from home, preferrably US Eastern, but +/- 2 hours timezone difference OK** - comfortable in start-up mentality
- entrepreneurial mindset

Open Therapeutics™ is a seven-year-old company that curates and develops open medical, biopharma, and synthetic biology-based biotechnologies. Among the technologies being freely opened to the global community are essential proteins for developing antibiotic and anticancer therapeutics, immunotherapy and oncolytics, and biomarker inducers. The Company is headquartered in Cincinnati, Ohio with laboratory operations in Covington, Kentucky, USA, and Madrid, Spain via its strategic partner, Bacmine SL.

Jan 11 2017 □ [Archived Version] □ Published at Caktus Blog

Python 3.6 was released in the tail end of 2016. Read on for a few highlights from this release. New module: secrets Python 3.6 introduces a new module in the standard library called secrets. While the random module has long existed to provide us with pseudo-random numbers suitable for applications like modeling and simulation, these...

Jan 11 2017 □ [Archived Version] □ Published at Dougal Matthews under tags flask frozen python static

Test

Jan 10 2017 □ [Archived Version] □ Published at Djangojobs.Net latest jobs

Agency life getting you down? Fed up of office politics and out of touch managers? Tired of being married to your desk?

We have a genuinely friendly and experienced team who will support you when you struggle and champion you when you nail it. Our directors don’t sit in glass offices making unrealistic demands, they sit at the desk next to us as our co-workers and argue over who shot first…*cough* *cough* Han!

Our company has and will continue to grow via the input and decisions of the entire team, based both on formal team meetings as well as impromptu chats at the kettle. Our office is fairly chilled and you will have 3 options; listen to the office radio with optional cross office chat, put your headphones in and listen to your own beats, or start an epic elastic band battle with the testers.

Oh yeah, we have testers! They are like our office siblings; we are best of friends but they do insist on breaking everything we own. It’s cool though, we don’t have a blame culture...we don’t find it to be very productive!

**What you’ll be getting up to:**

- Designing and building neat software for the web
- Chatting…
*ahem*we mean planning...with other members of the team - Solving dev world problems in the office...and real world problems in the pub!
- Working on a verity of solutions from e-commerce, bespoke applications, new products and for multiple industry sectors!

**What you’ll get in return:**

- When we say flexible hours we mean flexible hours!
- Private health insurance including dental and optical
- An extra day's holiday for each year of loyal service...long live The Empire!
- An invite to “The Real Coffee Club”, as well as their arch nemesis “The Biscuit Club”
- Free fruit to mellow out that caffeine and sugar come down
- Devs Assemble! Support from your fellow devs when the call comes
- Stability: Mercurytide is pushing 20 with a low staff turn around
- Pizza...tonnes of Pizza! Successful project? Pizza! New streamlined process? Pizza! matching socks? PIZZA!
- What you’ll need:

Ideally you’ll have experience with Python...and possibly Django Or several years experience with another object orientated language. There will be a small coding test which you can do at home...we want to get to know you and we believe you don’t truly know someone until you have read their code.

If that all sounds good then get in touch and we can have a proper chat.

Jan 09 2017 □ [Archived Version] □ Published at GoDjango Screencasts and Tutorials

Have you ever needed to quickly modify data or look it up. But while the task is simple the entire process of changing one value frustrates you?

Well, this is very common to me, bad UX is annoying. I quite often have to either lookup, or edit, two disparate, yet related pieces of data, and sometimes it is an exercise in frustration.

An all to common occurrence is I just needed to check the edit history of a "Company" our database. This is a simple process, go to the admin find the Company model, do a search and you have your answer.

Except, it isn't that easy in reality. Lets run through what really happened.

I went to "http://superawesomesite.com/admin/" and logged in.

I then looked at how my model options extended well below the fold of my browser so I had to scroll. No problem I'll just hit "ctrl+f" and search for it. WTF!!! where is my company model?

I then proceed to scroll down and finally find it only to remember it was pluralized. If I had searched for "Companies" I would have been good to go, grrrrr.

I click into and see the list of companies available to me. I see that there is a search feature at the top so I do a search for the relevant information. Unfortunately, I don't know the company name that is what I am trying to find out.

Except, we aren't filtering our search in the admin based on that field. So no results show up.

No problem I can do a list filter on the side. So I set the correct filters and still no luck because someone didn't set all the metadata that was supposed to be set for the company. Again grrrrr.

Finally, I abandoned the admin and opened up the django/python shell and did a query with the model, and in about 30 seconds had the record I needed. Took the id and plugged that into the django admin and I was good to go.

This was an exercise in frustration because the 30 seconds that was taken during development to decide which fields should be filtered didn't let that person imagine the field I needed. Also the fact that whomever added the company didn't add all the correct information, made it almost impossible to find the data. In the end I had to go outside this system that is hailed as one of the greatest tools for django to get the information I needed.

I propose we as a community reduce our reliance on the django admin, especially in production.

I also created a Video on the 5 reasons we shouldn't use the django admin.

Jan 09 2017 □ [Archived Version] □ Published at tuts+

When writing programs in our day-to-day life, we usually come across situations where we need to use a little maths to get the task done. Like other programming languages, Python provides various operators to perform basic calculations like `*`

for multiplication, `%`

for modulus, and `//`

for floor division.

If you are writing a program to perform specific tasks like studying periodic motion or simulating electric circuits, you will need to work with trigonometric functions as well as complex numbers. While you can't use these functions directly, you can access them by including two mathematical modules first. These modules are math and cmath.

The first one gives you access to hyperbolic, trigonometric, and logarithmic functions for real numbers, while the latter allows you to work with complex numbers. In this tutorial, I will go over all the important functions offered by these modules. Unless explicitly mentioned, all the values returned are floats.

These functions perform various arithmetic operations like calculating the floor, ceiling, or absolute value of a number using the `floor(x)`

, `ceil(x)`

, and `fabs(x)`

functions respectively. The function `ceil(x)`

will return the smallest integer that is greater than or equal to *x*. Similarly, `floor(x)`

returns the largest integer less than or equal to *x*. The `fabs(x)`

function returns the absolute value of *x*.

You can also perform non-trivial operations like calculating the factorial of a number using `factorial(x)`

. A factorial is the product of an integer and all the positive integers smaller than it. It is used extensively when dealing with combinations and permutations. It can also be used to calculate the value of sine and cosine functions.

import math def getsin(x): multiplier = 1 result = 0 for i in range(1,20,2): result += multiplier*pow(x,i)/math.factorial(i) multiplier *= -1 return result getsin(math.pi/2) # returns 1.0 getsin(math.pi/4) # returns 0.7071067811865475

Another useful function in the *math* module is `gcd(x,y)`

, which gives you the greatest common divisor (GCD) of two numbers *x* and *y*. When *x* and *y* are both not zero, this function returns the largest positive integer that divides both *x* and *y*. You can use it indirectly to calculate the lowest common multiple of two numbers using the following formula:

gcd(a, b) x lcm(a, b) = a x b

Here are a few of the arithmetic functions that Python offers:

import math math.ceil(1.001) # returns 2 math.floor(1.001) # returns 1 math.factorial(10) # returns 3628800 math.gcd(10,125) # returns 5 math.trunc(1.001) # returns 1 math.trunc(1.999) # returns 1

These functions relate the angles of a triangle to its sides. They have a lot of applications, including the study of triangles and the modeling of periodic phenomena like sound and light waves. Keep in mind that the angle you provide is in radians.

You can calculate `sin(x)`

, `cos(x)`

, and `tan(x)`

directly using this module. However, there is no direct formula to calculate `cosec(x)`

, `sec(x)`

, and `cot(x)`

, but their value is equal to the reciprocal of the value returned by `sin(x)`

, `cos(x)`

, and `tan(x)`

respectively.

Instead of calculating the value of trigonometric functions at a certain angle, you can also do the inverse and calculate the angle at which they have a given value by using `asin(x)`

, `acos(x)`

, and `atan(x)`

.

Are you familiar with the Pythagorean theorem? It states that that the square of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the other two sides. The hypotenuse is also the largest side of a right-angled triangle. The math module provides the `hypot(a, b)`

function to calculate the length of the hypotenuse.

import math math.sin(math.pi/4) # returns 0.7071067811865476 math.cos(math.pi) # returns -1.0 math.tan(math.pi/6) # returns 0.5773502691896257 math.hypot(12,5) # returns 13.0 math.atan(0.5773502691896257) # returns 0.5235987755982988 math.asin(0.7071067811865476) # returns 0.7853981633974484

Hyperbolic functions are analogs of trigonometric functions that are based on a hyperbola instead of a circle. In trigonometry, the points (cos *b*, sin *b*) represent the points of a unit circle. In the case of hyperbolic functions, the points (cosh *b*, sinh *b*) represent the points that form the right half of an equilateral hyperbola.

Just like the trigonometric functions, you can calculate the value of `sinh(x)`

, `cosh(x)`

, and `tanh(x)`

directly. The rest of the values can be calculated using various relations among these three values. There are also other functions like `asinh(x)`

, `acosh(x)`

, and `atanh(x)`

, which can be used to calculate the inverse of the corresponding hyperbolic values.

import math math.sinh(math.pi) # returns 11.548739357257746 math.cosh(math.pi) # returns 11.591953275521519 math.cosh(math.pi) # returns 0.99627207622075 math.asinh(11.548739357257746) # returns 3.141592653589793 math.acosh(11.591953275521519) # returns 3.141592653589793 math.atanh(0.99627207622075) # returns 3.141592653589798

Since `math.pi`

is equal to about 3.141592653589793, when we used `asinh()`

on the value returned by `sinh(math.pi)`

, we got our π back.

You will probably be dealing with powers and logarithms more often than hyperbolic or trigonometric functions. Fortunately, the *math* module provides a lot of functions to help us calculate logarithms.

You can use `log(x,[base])`

to calculate the log of a given number *x* to the given base. If you leave out the optional base argument, the log of x is calculated to the base e. Here, *e* is a mathematical constant whose value is 2.71828182.... and it can be accessed using `math.e`

. By the way, Python also allows you to access another constant π using `math.pi`

.

If you want to calculate the base-2 or base-10 logarithm values, using `log2(x)`

and `log10(x)`

will return more accurate results than `log(x, 2)`

and `log(x, 10)`

. Keep in mind that there is no `log3(x)`

function, so you will have to keep using `log(x, 3)`

for calculating base-3 logarithm values. The same goes for all other bases.

If the value whose logarithm you are calculating is very close to 1, you can use `log1p(x)`

. The `1p`

in `log1p`

signifies 1 plus. Therefore, `log1p(x)`

calculates `log(1+x)`

where x is close to zero. However, the results are more accurate with `log1p(x)`

.

You can also calculate the value of a number *x* raised to the power *y* by using `pow(x, y)`

. Before computing the powers, this function converts both the arguments to type float. If you want the final result to be computed in exact integer powers, you should use the built-in `pow()`

function or the `**`

operator.

You can also compute the square root of any given number *x* by using `sqrt(x)`

, but the same thing can also be accomplished by using `pow(x, 0.5)`

.

import math math.exp(5) # returns 148.4131591025766 math.e**5 # returns 148.4131591025765 math.log(148.41315910257657) # returns 5.0 math.log(148.41315910257657, 2) # returns 7.213475204444817 math.log(148.41315910257657, 10) # returns 2.171472409516258 math.log(1.0000025) # returns 2.4999968749105643e-06 math.log1p(0.0000025) # returns 2.4999968750052084e-06 math.pow(12.5, 2.8) # returns 1178.5500657314767 math.pow(144, 0.5) # returns 12.0 math.sqrt(144) # returns 12.0

Complex numbers are stored internally using rectangular or Cartesian coordinates. A complex number *z* will be represented in Cartesian coordinates as `z = x + iy`

, where *x* represents the real part and *y* represents the imaginary part. Another way to represent them is by using polar coordinates.

In this case, the complex number z would be defined a combination of the modulus *r* and phase angle *phi*. The modulus r is the distance between the complex number z and the origin. The angle phi is the counterclockwise angle measured in radians from the positive x-axis to the line segment joining *z* and the origin.

While dealing with complex numbers, the *cmath* module can be of great help. The modulus of a complex number can be calculated using the built-in `abs()`

function, and its phase can be calculated using the `phase(z)`

function available in the cmath module. You can convert a complex number in rectangular form to polar form using `polar(z)`

, which will return a pair `(r, phi)`

, where *r* is `abs(z)`

and phi is `phase(z)`

.

Similarly, you can convert a complex number in polar form to rectangular form using `rect(r, phi)`

. The complex number returned by this function is `r * (math.cos(phi) + math.sin(phi)*1j)`

.

import cmath cmath.polar(complex(1.0, 1.0)) # returns (1.4142135623730951, 0.7853981633974483) cmath.phase(complex(1.0, 1.0)) # returns 0.7853981633974483 abs(complex(1.0, 1.0)) # returns 1.4142135623730951

The *cmath* module also allows us to use regular mathematical functions with complex numbers. For example, you can calculate the square root of a complex number using `sqrt(z)`

or its cosine using `cos(z)`

.

import cmath cmath.sqrt(complex(25.0, 25.0)) # returns (5.49342056733905+2.2754493028111367j) cmath.cos(complex(25.0, 25.0)) # returns (35685729345.58163+4764987221.458499j)

Complex numbers have a lot of applications like modelling electric circuits, fluid dynamics, and signal analysis. If you need to work on any of those things, the *cmath* module won't disappoint you.

All of these functions we discussed above have their specific applications. For example, you can use the `factorial(x)`

function to solve permutation and combination problems. You can use the trigonometric functions to resolve a vector into Cartesian coordinates. You can also use trigonometric functions to simulate periodic functions like sound and light waves.

Similarly, the curve of a rope hanging between two poles can be determined using a hyperbolic function. Since all these functions are directly available in the *math* module, it makes it very easy to create little programs that perform all these tasks.

I hope you enjoyed this tutorial. If you have any questions, let me know in the comments.

Jan 07 2017 □ [Archived Version] □ Published at The Django weblog

We're happy to announce the winners of the DSF Board elections for 2017.

Frank Wiles, Daniele Procida, and James Bennett were re-elected for another term. Our new Board members are Kenneth Love, Ken W. Alger, and Rebecca Conley.

Rebecca, as you may be aware, served as Board Secretary during 2016 to fill a vacancy but will be returning again this year.

We wish to thank Christophe Pettus and Karen Tracey who did not run again this year for their service and the wisdom they brought to us.

The Board will be having our first meeting in the coming days to ratify the slate of officers at which time we'll update the website accordingly.

We look forward to another great year of helping further Django and the Django Community.