Category Archives: Advocacy

New in Python: Syntax for variable annotations

Python 3.6 added another interesting new feature that is known as Syntax for variable annotations. This new feature is outlined in PEP 526. The basic premise of this PEP is take the idea of Type Hinting (PEP 484) to its next logical step, which is basically adding option type definitions to Python variables, including class variables and instance variables. Please note that adding these annotations or definitions does not suddenly make Python a statically typed language. The interpreter still doesn’t care what type the variable is. However, a Python IDE or other utility like pylint could have an annotation checker added to them that could highlight when you use a variable that you have annotated as one type and then used incorrectly by changing its type mid-function.

Let’s look at a simple example so we can see how this works:

# annotate.py
name: str = 'Mike'

Continue reading New in Python: Syntax for variable annotations

New in Python: Underscores in Numeric Literals

Python 3.6 added some interesting new features. The one that we will be looking at in this article comes from PEP 515: Underscores in Numeric Literals. As the name of the PEP implies, this basically gives you the ability to write long numbers with underscores where the comma normally would be. In other words, 1000000 can now be written as 1_000_000. Let’s take a look at some simple examples:

>>> 1_234_567
1234567
>>>'{:_}'.format(123456789)
'123_456_789'
>>> '{:_}'.format(1234567)
'1_234_567'

The first example just shows how Python interprets a large number with underscores in it. The second example demonstrates that we can now give Python a string formatter, the “_” (underscore), in place of a comma. The results speak for themselves.

The numeric literals that include underscores behave the same way as normal numeric literals when doing calculations:

>>> 120_000 + 30_000
150000
>>> 120_000 - 30_000
90000

The Python documentation and the PEP also mention that you can use the underscores after any base specifier. Here are a couple of examples taken from the PEP and the documentation:

>>> flags = 0b_0011_1111_0100_1110
>>> flags
16206
>>> 0x_FF_FF_FF_FF
4294967295
>>> flags = int('0b_1111_0000', 2)
>>> flags
240

There are some notes about the underscore that need to be mentioned:

  • You can only use one consecutive underscore and it has to be between digits and after any base specifier
  • Leading and trailing underscores are not allowed

This is kind of a fun new feature in Python. While I personally don’t have any use cases for this in my current job, hopefully you will have one at yours.

PyDev of the Week: Glyph Lefkowitz

This week we welcome Glyph Lefkowitz (@glyph) as our PyDev of the Week! Glyph is the creator / maintainer of Twisted, an asynchronous event-driven networking engine. Glyph finds the time to write a blog that you might find quite interesting. You can also check out Github to see what projects he’s involved with. Let’s spend a few minutes getting to know Glyph better!

Can you tell us a little about yourself (hobbies, education, etc):

I’m just this guy, you know?

I work on a lot of open source software, both for work – I maintain Twisted, and a ton of associated ecosystem projects, for Rackspace – and personally.

My hobbies mainly revolve around computers. For example, I’m an avid video game fan. I’ve also dabbled in graphic design, 3D rendering, and computer-generated music; although nothing really good enough to share. As time allows, I’m also a really big reader, particularly of science fiction and fantasy.

In summary, I’m a nerd in the classic sense. To complete the caricature, my wife is also a programmer and so my personal life revolves around computer technology as well. We both also have a strong interest in information security, so I spend a fair amount of time ensuring that our systems are up to date, our passwords are rotated, and so on.

Continue reading PyDev of the Week: Glyph Lefkowitz

PyDev of the Week: Katie McLaughlin

This week we welcome Katie McLaughlin (@glasnt) as our PyDev of the Week! She is a core developer of the BeeWare project. You should take a moment and check out her Github profile to see what fun projects she’s a part of. Katie also has a fun little website and was a speaker at PyCon 2016. Let’s take a few moments to get to know her better!

katie

Can you tell us a little about yourself (hobbies, education, etc):

G’day! I’m Australian, originally from Brisbane, but now living in Sydney. I’ve got a Bachelor of Information Technology, and I’ve been in the tech industry for going on ten years now. I’ve been in a bunch of different roles and technologies, but mostly in web hosting and cloud stuff. When I’m not on a computer or attending conferences, I enjoy cooking and making tapestries.

Why did you start using Python?

To fix a bug in a bit of in-house code! There was a bug in an old script, and I saw the “#!/usr/bin/env python” and learnt from there. I didn’t go back to Python for a few years, but just after I was accepted to PyCon Australia 2015, I thought I should brush up on what little I knew. That’s about a year ago now, and it’s now my go-to language for scripting. I was had previously used Ruby for years, and I only occasionally still automatically type “puts” instead of “print”.

Continue reading PyDev of the Week: Katie McLaughlin

PyDev of the Week: Damien George

This week we welcome Damien George as our PyDev of the Week! Damien is the man behind the MicroPython project which allows you to run a version of Python on microcontrollers. You can learn more about Damien on his website or by visiting his Github page. Let’s spend some time getting to know our fellow Pythonista better!

damien

Can you tell us a little about yourself (hobbies, education, etc):

I grew up in Melbourne, Australia and started playing with computers and electronics pretty early on. I had a Commodore 64 when I was young and remember borrowing books from the local library on how to program it in assembler. Really it just gave you a bunch of “data” statements to type in, but in the end you could make some pretty cool stuff. In high school I liked physics and maths and then I went to university and did degrees in both science and engineering. I majored in physics and computer engineering and then did a PhD in physics, after which I moved to the Netherlands, and eventually the UK, to do research in theoretical high-energy physics (extra dimensions, supersymmetry, cosmology, things like that). During my career as a physicist I kept an active interest in programming and robotics, with lots of side projects including a self-made CNC machine (see http://dpgeorge.net/cnc/).

Continue reading PyDev of the Week: Damien George

PyDev of the Week: Ben Bangert

This week we welcome Ben Bangert as our PyDev of the Week! Ben is the mastermind behind the Pylons project, which was a web framework in Python. It is now known as Pyramid. If you have a moment or two, you should check out Ben’s website or his Github profile to see what he’s been up to. Let’s spend some time learning more about him!

Can you tell us a little about yourself (hobbies, education, etc):

I’ve been programming professionally for about 17 years. I graduated from Sonoma State University with a Philosophy degree in 2001, and have been living in beautiful Sonoma County ever since. I live here with my wife, son, and two dogs, whom I regularly take on walks throughout the day. When the weather is good I like to BBQ, go on hikes, and take trips out to the local county parks.

Continue reading PyDev of the Week: Ben Bangert

PyDev of the Week: Larry Hastings

This week we welcome Larry Hastings as our PyDev of the Week! Larry is a core Python developer and long time user of Python. He has a fun talk about Python’s GIL on Youtube that is well worth your time checking out. He is also the mastermind behind the now defunct Radio Free Python podcast. Let’s take a few moments to get to know him better!

Can you tell us a little about yourself (hobbies, education, etc):

I have a Bachelor of Arts in Computer And Information Sciences from the University of California, Santa Cruz. Why it’s a bachelor of arts in computer science has always baffled me–but that’s UCSC for you.


Why did you start using Python?

I started using Python back in the late 90s. Back then I was a professional Windows developer, and at the time Python’s support for Windows was far better than the other scripting languages–Perl on Windows was a distant also-ran to Perl on UNIX. Also, after shipping a decent-sized project on Perl (the web-based signup process for a small ISP), I swore off Perl. Never again! I haven’t touched it since.

I don’t remember specifically my first project–it was so long ago that I honestly don’t remember. I remember the first time I heard about Python, though. My brother Stuart wanted to buy a used boat, and he used Python to scrape a local newspaper’s classified ads to find interesting offers. Naturally I had the same initial reaction to Python everybody does–“that whitespace thing is too weird”–but once I started using the language I quickly got over it.

Continue reading PyDev of the Week: Larry Hastings

PyDev of the Week: Barry Warsaw

This week we welcome Barry Warsaw (@pumpichank) as our PyDev of the Week! Barry works on the Ubuntu operating system for Canonical and he’s the project leader for GNU Mailman. He also used to be the lead maintainer for the Jython project. If you have the time, you should check out his website. Barry’s Github page is also worth a look to see what projects he finds interesting or you can check out his personal projects on Gitlab. Let’s take a few minutes to find out more about our fellow Pythonista!

Can you tell us a little about yourself (hobbies, education, etc):

I work for Canonical on the Ubuntu Foundations team, so we take care of the plumbing layer of Ubuntu. Roughly, it’s stuff like toolchains (interpreters, compilers, language runtimes, etc.), image building, installers, and general archive goodness. I try to keep the Python stack happy and over the last few Ubuntu releases have really been concentrating on switching Ubuntu to Python 3. I’m also a Debian Developer, so a lot of the more general work on Python happens there first, and then gets imported automatically into Ubuntu. We get especially busy when new Python versions are released, ensuring that transitions go smoothly. At work I’m also responsible for the “system image updater client” which is the piece of the Ubuntu Touch flavor that performs the atomic system upgrades on Ubuntu phones and tablets.

On the side, I’m a semi-professional musician, playing bass in several local bands, doing studio work for local artists, and writing in my own home studio. I’m also a tai chi practitioner for the last 15 years or so, studying Yang style short form, sword, push hands, and more recently qi gong.

Continue reading PyDev of the Week: Barry Warsaw

PyDev of the Week: Amber Brown

This week we welcome Amber Brown (@hawkieowl) as our PyDev of the Week. Amber is one of the core developers of the Twisted package. She has a fun little twisted blog that you might enjoy checking out. You can also see what Amber’s been up to by checking out her Github profile. She has also been interviewed by DjangoGirls. Let’s take a few moments to get to know her better!

Can you tell us a little about yourself (hobbies, education, etc):

I’m an Australian, born in Perth, but ultimately hailing from several small country towns along the west. I’m self-educated in software development and IT, and worked for half a decade in local government as IT, and the past three years in software development full-time. My hobbies are board/card games (Go and MTG, mostly!), video games (Factorio, XCOM 2), and the occasional photography. Programming isn’t so much a hobby for me as a life; it’s questionably healthy for me, I’m sure, but it is what it is! The most surprising aspect of me is generally my age, being 22. My middle name is Hawkie (from HawkOwl, my handle), and like most trans women, I enjoy salt and puns.

Continue reading PyDev of the Week: Amber Brown

PyDev of the Week: Georg Brandl

This week we welcome Georg Brandl (@birkenfeld) as our PyDev of the Week. Georg is a core developer of the Python language and has been for over 10 years. He is also a part of the Pocoo team. You can see what projects get him excited by checking out his Github profile. Let’s take a few moments to learn more about him!

Can you tell us a little about yourself (hobbies, education, etc):

I studied physics and during my PhD project was working at a large German research center, where software is a big part of conducting research, and external scientists come and use our facilitiy for their own experiments. Meanwhile I’m still at the same place, but working on that software as my main job. We’re using Python extensively, basically giving our guests a highly fancified Python shell as the main user interface.

Continue reading PyDev of the Week: Georg Brandl