Category Archives: Python

Is related to the Python Programming language in some way

Python 101 is now a Course on Educative

My first book, Python 101, has been made into an online course on the educative website. Educative is kind of like Code Academy in that you can run the code snippets from the book to see what kind of output they produce. You can edit the examples that are executable, but you cannot save your edits currently. You can get 50% off of the course by using the following coupon code: au-pythonlibrary50 (note: This coupon is only good for one week)

Python 101 is for primarily aimed at people who have an understanding of programming concepts or who have programmed with another language already. I do have a lot of readers that are completely new to programming who have enjoyed the book too though. The book itself is split into 5 distinct parts:

Part one covers the basics of Python. Part two moves into learning a little of Python’s standard library. In this section, I cover the libraries that I find myself using the most on a day-to-day basis. Part three moves into intermediate level territory and covers various topics such as decorators, debugging, code profiling and testing your code. Part four introduces the reader to installing 3rd party libraries and briefly demonstrates some of the popular ones, such as lxml, requests, SQLAlchemy and virtualenv. The last section is all about distributing your code. Here you will learn how to add your code to Python Package Index as well as create Windows executables.

For a full table of contents, you can visit the book’s web page here. Educative also has a really good contents page for the online course too.

PyDev of the Week: Cameron Simpson

This week we welcome Cameron Simpson as our PyDev of the Week. Cameron is the co-author of PEP 418 – Add monotonic time, performance counter, and process time functions and the author of PEP 499 – python -m foo should bind sys.modules[‘foo’] in addition to sys.modules[‘__main__’]. He is also a core Python developer and enthusiast. You can check out some of his projects on bitbucket. Let’s take a few moments to get to know him better!

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

I’ve been a programming nerd since I was about 15, and I’ve got a BSc in Computer Science. I’m a somewhat lapsed climber and biker; I still have a motorcycle and try to use it but circumstances interfere; I’m trying to resume some indoor climbing too. I’m spending a fair amount of time on a small farm, and teleworking from there part of the time; I’ve been fortunate to find work where that is possible.

Continue reading PyDev of the Week: Cameron Simpson

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: Oleg Broytman

This week we welcome Oleg Broytman (@phd_ru) as our PyDev of the Week. Oleg is the maintainer of the SQLObject project. According to their website “SQLObject is a popular Object Relational Manager for providing an object interface to your database, with tables as classes, rows as instances, and columns as attributes.“. You can also see what else Oleg is a part of via Github and his website. Let’s take a few moments to get to know Oleg better!

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

I was born in Central Asian part of Soviet Union. I relocated to Moscow, Russia to study computer science at CS department of Moscow State University. I started to program before IBM PC era, my first computers were Soviet clones of PDP-11 and IBM/360.

Outside of my professional job I spend a lot of time with computers taking parts in Free Software projects.

Other than that I live usual life spending time with my family, reading books, listening music, watching videos.

Continue reading PyDev of the Week: Oleg Broytman

wxPython Cookbook Artist Interview: Liza Tretyakova

I always put a lot of thought into the covers of my book. For my first book on wxPython, I thought it would be fun to do a cookbook because I already had a lot of recipes on my blog. So I went with the idea of doing a cookbook. For the cover, my first thought was to have some kind of kitchen scene with mice cooks. Then I decided that was too obvious and decided to go with the idea of an Old West cover with cowboy (or cow mice) cooking at a fire.

I asked Liza Tretyakova, my cover artist for wxPython Cookbook, to do a quick interview about herself. Here is what she had to say:

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

My name is Liza Tretyakova, I’m a free-lance illustrator currently working in Moscow.

Education:

  • Moscow State University, Faculty of History of Arts
  • BA(Hons) Illustration, University of Plymouth


I work as an illustrator for about 10 years. I love horses and I used to have a horse. Also I’m interested in archery. I like reading and spending a lot of time with my daughter Yara, who is 7 years old.

What motivated you to be an illustrator versus some other profession?

Since I was a child I have been drawing all the time and it just happened that I started to work as an illustrator, it turned into a profession.

What process do you go through when you are creating a new piece of art?

It is different every time, there is no specific “recipe” 🙂

Do you have any advice for someone who wants to be an illustrator?

You should try to draw every day, the more the better.

Do you have anything else you would like to say?

It was a pleasure working with you!

Thanks so much for doing the interview and for agreeing to be my illustrator for my wxPython Cookbook.

You can see more of Liza’s work on Behance.

PyDev of the Week: Ivan Levkivskyi

This week we welcome Ivan Levkivskyi (@ILevkivskyi) as our PyDev of the Week! Ivan is the author or coauthor of several Python Enhancement Proposals, specifically 483, 484 and 526. In other words, Ivan is one of the lead developers behind adding type hints to Python via the typing module. Ivan is a scientist and as such, he has written a lot of interesting research papers, which I will readily admit that they are over my head. You might also find his Github page interesting as he is involved in a lot of projects. Let’s take some time to get to know our fellow Pythonista better!

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

I work as a researcher in theoretical physics. I was more interested in mathematical physics in high school, but now I mostly interested in mesoscopic physics — area that investigates the boundaries between our macroscopic world and the quantum microscopic world. I have been learning physics for about 20 years and never had any CS education. Although, I should note that my rough familiarity with category theory helps me in the programming world.

Most of the time, programming was rather my hobby, only the last 5 years I have been programming for work. My first acquaintance with programming was learning x86 assembly at an age of 10. Then I played with other languages from time to time. And now I use Python a lot in my work, mostly for prototyping and number-crunching.

I am from Ukraine originally, but now live in Switzerland. Apart from physics and programming, I like mountain sports: hiking, rock climbing, ski touring, etc. Also I like listening to music a lot and I used to play accordion and bass.

Continue reading PyDev of the Week: Ivan Levkivskyi

wxPython Cookbook is Officially Released!

I recently finished up Mmy third book, wxPython Cookbook and I am officially releasing it today. My wxPython Cookbook is my longest book yet, clocking in at over 340 pages and over 50 recipes. I have a full table of contents on Leanpub for anyone who is interested in the nitty gritty details.

Here are the current places that you can get a copy of the book:

Thanks so much to all my readers and Kickstarter backers who have encouraged me throughout the writing process.

PyDev of the Week: Philip House

This week we welcome Philip House (@PhilipHouse2) as our PyDev of the Week! Philip is one of the authors behind PEP 526 – Syntax for Variable Annotations which was provisionally accepted into Python 3.6. Philip also writes a blog and is involved in the development of several 3rd party Python packages which you can check out on Github. Let’s take some time to get to know him better.

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

I graduated from Northwestern University in 2015 where I studied computer science for my degree program. During my time there, I was mainly interested in learning about how the web and distributed computing works. Some of my favorite work in undergrad was doing research on and building crowdsourcing and social computing systems. I was particularly curious about learnersourcing – solving problems with a crowd of motivated learners.

From internships and personal projects in college, I built up experience building web applications and data-intensive projects. When I graduated, I went to work as a platform software engineer where I worked with building API’s and highly available distributed services with a mixture of Python and Java.

I’m currently working on a startup with some former classmates in the industrial IoT space.

When I’m not sitting in front of a computer, I really enjoy camping with friends and playing old-school Gamecube games.

Continue reading PyDev of the Week: Philip House

PyDev of the Week: Jacob Vanderplas

This week we welcome Jacob Vanderplas (@jakevdp) as our PyDev of the Week! Jacob is the author of Python Data Science Handbook: Essential Tools for Working with Data and works at the University of Washington as a researcher and teacher. As you might have guessed from the title of his book, Jacob is very much in tune with the Scientific programming projects in Python. If you check out his github profile, you will find many interesting highlights on Scikit-learn, for example. Let’s take some time to get to know him better!

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

I’ve always been drawn to physical activity – I was a swimmer in high school and college, and post-college got into triathlons, culminating with an Ironman a few years back. I’m not as competition-driven these days, but the way I relax is to go out on long hikes, runs, swims, or bike rides. My favorite pastime is to head out on long trail-runs deep into the mountains, though I don’t make it out as much these days with a toddler at home!

I was born and raised in Palo Alto, majored in Physics at Calvin College and did my PhD in Astronomy at University of Washington. In between I lived for a year in Northern Japan, guided mountaineering excursions for two summers in the Sierra Nevada, and taught at a middle school outdoor science program for two years in the redwood forests above Santa Cruz – my experiences during those years and the people with whom I shared my time have had a profound impact on me, and I’m so grateful for the opportunities I’ve had!

Continue reading PyDev of the Week: Jacob Vanderplas