<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:og="http://ogp.me/ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:schema="http://schema.org/" xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:sioct="http://rdfs.org/sioc/types#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" version="2.0" xml:base="https://www.linuxjournal.com/">
  <channel>
    <title>python</title>
    <link>https://www.linuxjournal.com/</link>
    <description/>
    <language>en</language>
    
    <item>
  <title>Experimenting with Python implementation of Host Identity Protocol</title>
  <link>https://www.linuxjournal.com/content/experimenting-python-implementation-host-identity-protocol</link>
  <description>  &lt;div data-history-node-id="1340845" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-field-node-image field--type-image field--label-hidden field--item"&gt;  &lt;img loading="lazy" src="https://www.linuxjournal.com/sites/default/files/nodeimage/story/experimenting-with-python-implementation-of-host-identity-protocol.jpg" width="850" height="500" alt="Experimenting with Python implementation of Host Identity Protocol" typeof="foaf:Image" class="img-responsive" /&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/dmitriy-kuptsov" lang="" about="https://www.linuxjournal.com/users/dmitriy-kuptsov" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Dmitriy Kuptsov&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;Host Identity Protocol, or HIP, is a layer 3.5 solution and was initially designed to split the dual role of the IP address - locator and identifier. Using HIP protocol one can solve not only mobility problems but also establish authenticated secure channel between two communicating end-hosts. In this short article, we first introduce relevant background information. We then present some mathematical background related to Elliptic Curve (EC) Cryptography and Diffie-Hellman protocol based on EC. Finally, we demonstrate some micro benchmarking results for various cryptographic primitives and conclude the article with the results for the overall performance of HIP and IPSec, which we implemented in Linux userspace using Python language.&lt;/p&gt;

&lt;span class="h3-replacement"&gt;INTRODUCTION&lt;/span&gt;

&lt;p&gt;Sometimes it is easier to implement prototypes in userspace using high-level languages, such as Python or Java. In this document we attempt to describe our implementation effort related to Host Identity Protocol version 2. In the first part, we describe various security solutions, then we discuss some implementation details of the HIP protocol, and finally, in the last part of this work we discuss the performance of the HIP and IPSec protocols implemented using Python language.&lt;/p&gt;

&lt;span class="h3-replacement"&gt;BACKGROUND&lt;/span&gt;

&lt;p&gt;In this section we will describe basic background. First, we will discuss the problem of mobile Internet and introduce the Host Identity Protocol. We then move to the discussion of various security protocols. We will conclude the section with the discussion of Elliptic Curves and a variant of Diffie-Hellman algorithm, which uses EC cryptography (ECC).&lt;/p&gt;

&lt;p&gt;Internet was designed initially so that the Internet Protocol (IP) address is playing dual role: it is the locator, so that the routers can find the recipient of a message, and it is an identifier, so that the upper layer protocols (such as TCP and UDP) can make bindings (for example, transport layer sockets use IP addresses and ports to make a connections). This becomes a problem when a networked device roams from one network to another, and so the IP address changes, leading to failures in upper layer connections. The other problem is establishment of the authenticated channel between the communicating parties. In practice, when making connections, long term identities of the parties are not verified. Of course, there are solutions such as SSL which can readily solve the problem at hand. However, SSL is suitable only for TCP connections and most of the time practical use cases include only secure web surfing and establishment of VPN tunnels. Host Identity Protocol on the other hand is more flexible: it allows peers to create authenticated secure channel on network layer, and so all upper layer protocols can benefit from such channel.&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/experimenting-python-implementation-host-identity-protocol" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Thu, 26 Aug 2021 16:00:00 +0000</pubDate>
    <dc:creator>Dmitriy Kuptsov</dc:creator>
    <guid isPermaLink="false">1340845 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Understanding Python's asyncio</title>
  <link>https://www.linuxjournal.com/content/understanding-pythons-asyncio</link>
  <description>  &lt;div data-history-node-id="1340725" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/reuven-m-lerner" lang="" about="https://www.linuxjournal.com/users/reuven-m-lerner" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Reuven M. Lerner&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;How to get started using Python's asyncio.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
Earlier this year, I attended PyCon, the international Python
conference. One topic, presented at numerous talks and discussed
informally in the hallway, was the state of threading in Python—which
is, in a nutshell, neither ideal nor as terrible as some critics would
argue.
&lt;/p&gt;

&lt;p&gt;
A related topic that came up repeatedly was that of "asyncio", a
relatively new approach to concurrency in Python. Not only were there
formal presentations and informal discussions about asyncio, but a
number of people also asked me about courses on the subject.
&lt;/p&gt;

&lt;p&gt;
I must admit, I was a bit surprised by all the interest. After
all, asyncio isn't a new addition to Python; it's been around for a
few years. And, it doesn't solve all of the problems associated with
threads. Plus, it can be confusing for many people to get started with it.
&lt;/p&gt;

&lt;p&gt;
And yet, there's no denying that after a number of years when
people ignored asyncio, it's starting to gain steam. I'm sure
part of the reason is that asyncio has matured and improved over time,
thanks in no small part to much dedicated work by countless developers.
But, it's also because asyncio is an increasingly good and useful choice
for certain types of tasks—particularly tasks that work across
networks.
&lt;/p&gt;

&lt;p&gt;
So with this article, I'm kicking off a series on asyncio—what it is, how to
use it, where it's appropriate, and how you can and should (and also can't
and shouldn't) incorporate it into your own work.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
What Is asyncio?&lt;/span&gt;

&lt;p&gt;
Everyone's grown used to computers being able to do more than one thing at a
time—well, sort of. Although it might seem as though computers are
doing more than one thing at a time, they're actually switching, very
quickly, across different tasks. For example, when you &lt;code&gt;ssh&lt;/code&gt; in to a Linux
server, it might seem as though it's only executing your commands. But
in actuality, you're getting a small "time slice" from the CPU, with the
rest going to other tasks on the computer, such as the systems that
handle networking, security and various protocols. Indeed, if you're
using SSH to connect to such a server, some of those time slices
are being used by &lt;code&gt;sshd&lt;/code&gt; to handle your connection and even allow you to
issue commands.
&lt;/p&gt;

&lt;p&gt;
All of this is done, on modern operating systems, via "pre-emptive
multitasking". In other words, running programs aren't given a choice of
when they will give up control of the CPU. Rather, they're forced to
give up control and then resume a little while later. Each process
running on a computer is handled this way. Each process can, in turn,
use threads, sub-processes that subdivide the time slice given to their
parent process.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/understanding-pythons-asyncio" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Wed, 07 Aug 2019 22:00:00 +0000</pubDate>
    <dc:creator>Reuven M. Lerner</dc:creator>
    <guid isPermaLink="false">1340725 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>DNA Geometry with cadnano</title>
  <link>https://www.linuxjournal.com/content/dna-geometry-cadnano</link>
  <description>  &lt;div data-history-node-id="1340744" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/joey-bernard" lang="" about="https://www.linuxjournal.com/users/joey-bernard" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Joey Bernard&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;
This article introduces a tool you can use to work on three-dimensional DNA origami. The package is called &lt;a href="https://cadnano.org"&gt;cadnano&lt;/a&gt;, and it's currently
being developed at the Wyss Institute. With this package, you'll be
able to construct and manipulate the three-dimensional representations
of DNA structures, as well as generate publication-quality graphics of
your work.
&lt;/p&gt;

&lt;p&gt;
Because this software is research-based, you won't likely find
it in the package repository for your favourite distribution, in which
case
you'll need to install it from the GitHub
repository.
&lt;/p&gt;

&lt;p&gt;
Since cadnano is a Python
program, written to use the Qt framework, you'll need to install
some packages first. For example, in Debian-based distributions, you'll
want to run the following commands:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
sudo apt-get install python3 python3-pip
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
I found that installation was a bit tricky, so I created a virtual Python
environment to manage module installations.
&lt;/p&gt;

&lt;p&gt;
Once you're in your activated
virtualenv, install the required Python modules with the
command:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
pip3 install pythreejs termcolor pytz pandas pyqt5 sip
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
After those dependencies are installed, grab the source code with
the command:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
git clone https://github.com/cadnano/cadnano2.5.git
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
This will grab the Qt5 version. The Qt4 version is in the repository
&lt;a href="https://github.com/cadnano/cadnano2.git"&gt;https://github.com/cadnano/cadnano2.git&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Changing directory into the
source directory, you can build and install cadnano with:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
python setup.py install
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
Now your cadnano should be available within the virtualenv.
&lt;/p&gt;

&lt;p&gt;
You can start cadnano simply by executing the &lt;code&gt;cadnano&lt;/code&gt;
command from
a terminal window. You'll see an essentially blank
workspace, made up of several empty view panes and an empty inspector
pane on the far right-hand side.
&lt;/p&gt;

&lt;img src="https://www.linuxjournal.com/sites/default/files/styles/max_650x650/public/u%5Buid%5D/cadnano1.png" width="650" height="445" alt="""" class="image-max_650x650" /&gt;&lt;p&gt;
&lt;em&gt;Figure 1. When you first start cadnano, you get a completely
blank work space.&lt;/em&gt;
&lt;/p&gt;

&lt;p&gt;
In order to walk through a few of
the functions available in cadnano, let's create
a six-strand nanotube. The first step is to create a background that
you can use to build upon. At the top of the main window, you'll find
three buttons in the toolbar that will let you create a "Freeform",
"Honeycomb" or "Square" framework. For this example,
click the honeycomb button.
&lt;/p&gt;

&lt;img src="https://www.linuxjournal.com/sites/default/files/styles/max_650x650/public/u%5Buid%5D/cadnano2.png" width="650" height="434" alt="""" class="image-max_650x650" /&gt;&lt;p&gt;
&lt;em&gt;Figure 2. Start your construction with one of the
available geometric frameworks.&lt;/em&gt;
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/dna-geometry-cadnano" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Wed, 07 Aug 2019 19:30:00 +0000</pubDate>
    <dc:creator>Joey Bernard</dc:creator>
    <guid isPermaLink="false">1340744 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Python's Mypy: Callables and Generators</title>
  <link>https://www.linuxjournal.com/content/pythons-mypy-callables-and-generators</link>
  <description>  &lt;div data-history-node-id="1340661" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/reuven-m-lerner" lang="" about="https://www.linuxjournal.com/users/reuven-m-lerner" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Reuven M. Lerner&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;Learn how Mypy's type checking works with functions and
generators.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
In my last two articles I've described some of the ways Mypy,
a type checker for Python, can help identify potential problems
with your code. [See &lt;a href="https://www.linuxjournal.com/content/introducing-mypy-experimental-optional-static-type-checker-python"&gt;"Introducing
Mypy, an Experimental Optional Static Type Checker for Python"&lt;/a&gt; and &lt;a href="https://www.linuxjournal.com/content/pythons-mypy-advanced-usage"&gt;"Python's
Mypy—Advanced Usage"&lt;/a&gt;.] For people (like me) who have enjoyed dynamic languages
for a long time, Mypy might seem like a step backward. But given the
many mission-critical projects being written in Python, often by large
teams with limited communication and Python experience, some kind of
type checking is an increasingly necessary evil.
&lt;/p&gt;

&lt;p&gt;
It's important to remember that Python, the language, isn't changing,
and it isn't becoming statically typed. Mypy is a separate program, running
outside Python, typically as part of a continuous integration (CI)
system or invoked as part of a Git commit hook. The idea is that Mypy
runs before you put your code into production, identifying where the
data doesn't match the annotations you've made to your variables and
function parameters.
&lt;/p&gt;

&lt;p&gt;
I'm going to focus on a few of Mypy's advanced features here. You
might not encounter them very often, but even if you don't, it'll give
you a better picture of the complexities associated with type checking,
and how deeply the Mypy team is thinking about their work, and what
tests need to be done.  It'll also help you understand more about the ways
people do type checking, and how to balance the beauty,
flexibility and expressiveness of dynamic typing with the strictness
and fewer errors of static typing.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Callable Types&lt;/span&gt;

&lt;p&gt;
When I tell participants in my Python classes that everything in Python
is an object, they nod their heads, clearly thinking, "I've heard this
before about other languages." But then I show them that functions and
classes are both objects, and they realize that Python's notion of
"everything" is a bit more expansive than theirs.  (And yes, Python's
definition of "everything" isn't as wide as Smalltalk's.)
&lt;/p&gt;

&lt;p&gt;
When you define a function, you're creating a new object, one of type
"function":

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
&gt;&gt;&gt; def foo():
...     return "I'm foo!"

&gt;&gt;&gt; type(foo)
&lt;class 'function'&gt;
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
Similarly, when you create a new class, you're adding a new object type
to Python:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
&gt;&gt;&gt; class Foo():
...     pass

&gt;&gt;&gt; type(Foo)
&lt;class 'type'&gt;
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
It's a pretty common paradigm in Python to write a function that, when
it runs, defines and runs an inner function. This is also known as a
"closure", and it has a few different uses.  For example, you can write:

&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/pythons-mypy-callables-and-generators" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Mon, 29 Jul 2019 11:00:00 +0000</pubDate>
    <dc:creator>Reuven M. Lerner</dc:creator>
    <guid isPermaLink="false">1340661 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>An AI Wizard of Words</title>
  <link>https://www.linuxjournal.com/content/ai-wizard-words</link>
  <description>  &lt;div data-history-node-id="1340681" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/marcel-gagn%C3%A9" lang="" about="https://www.linuxjournal.com/users/marcel-gagn%C3%A9" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Marcel Gagné&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;A look at using OpenAI's Generative Pretrained Transformer 2 (GPT-2) to generate text.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
It's probably fair to say that there's more than one person out there who is
worried about some version of artificial intelligence, or AI, possibly in a
robot body of some kind, taking people's jobs. Anything that is repetitive or
easily described is considered fair game for a robot, so driving a car or
working in a factory is fair game.
&lt;/p&gt;

&lt;p&gt;
Until recently, we could tell ourselves that people like yours truly—the
writers and those who create things using some form of creativity—were more
or less immune to the march of the machines. Then came GPT-2, which stands for
Generative Pretrained Transformer 2. I think you'll agree, that isn't the
sexiest name imaginable for a civilization-ending text bot. And since it's
version 2, I imagine that like &lt;em&gt;Star Trek&lt;/em&gt;'s M-5 computer, perhaps GPT-1 wasn't
entirely successful. That would be the original series episode titled, "The
Ultimate Computer", if you want to check it out.
&lt;/p&gt;

&lt;p&gt;
So what does the name "GPT-2" stand for? Well, "generative" means
pretty much what it sounds like. The program generates text based on a
predictive model, much like your phone suggests the next word as you type.
The "pretrained" part is also quite obvious in that the model released by
OpenAI has been built and fine-tuned for a specific purpose. The last word,
"Transformer", refers to the "transformer architecture", which is a neural network
design architecture suited for understanding language. If you want to dig
deeper into that last one, I've included a link from a Google AI blog that
compares it to other machine learning architecture (see Resources).
&lt;/p&gt;

&lt;p&gt;
On February 14, 2019, Valentine's Day, OpenAI released GPT-2 with a
warning:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;
Our model, called GPT-2 (a successor to GPT), was trained simply to predict
the next word in 40GB of Internet text. Due to our concerns about malicious
applications of the technology, we are not releasing the trained model. As an
experiment in responsible disclosure, we are instead releasing a much smaller
model for researchers to experiment with, as well as a technical paper.
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
I've included a link to the blog in the Resources section at the end of this
article. It's worth
reading partly because it demonstrates a sample of what this software is
capable of using the full model (see Figure 1 for a sample). We already have
a problem with human-generated fake news; imagine a tireless machine capable
of churning out vast quantities of news and posting it all over the internet, and you start to get a feel for the dangers. For that reason, OpenAI released
a much smaller model to demonstrate its capabilities and to engage
researchers and developers.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/ai-wizard-words" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Mon, 15 Jul 2019 11:00:00 +0000</pubDate>
    <dc:creator>Marcel Gagné</dc:creator>
    <guid isPermaLink="false">1340681 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Python's Mypy--Advanced Usage</title>
  <link>https://www.linuxjournal.com/content/pythons-mypy-advanced-usage</link>
  <description>  &lt;div data-history-node-id="1340606" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/reuven-m-lerner" lang="" about="https://www.linuxjournal.com/users/reuven-m-lerner" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Reuven M. Lerner&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;Mypy can check more than simple Python types.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
In &lt;a href="https://www.linuxjournal.com/content/introducing-mypy-experimental-optional-static-type-checker-python"&gt;my
last article&lt;/a&gt;, I introduced Mypy, a package that enforces type checking in
Python programs. Python itself is, and always will remain, a
dynamically typed language. However, Python 3 supports "annotations", a
feature that allows you to attach an object to variables, function
parameters and function return values. These annotations are ignored by
Python itself, but they can be used by external tools.
&lt;/p&gt;

&lt;p&gt;
Mypy is one such tool, and it's an increasingly popular one. The idea is that
you run Mypy on your code before running it. Mypy looks at your code
and makes sure that your annotations correspond with actual usage. In
that sense, it's far stricter than Python itself, but that's the whole
point.
&lt;/p&gt;

&lt;p&gt;
In &lt;a href="https://www.linuxjournal.com/content/introducing-mypy-experimental-optional-static-type-checker-python"&gt;my last article&lt;/a&gt;, I covered some basic uses for Mypy. Here, I want
to expand upon those basics and show how Mypy really digs deeply
into type definitions, allowing you to describe your code in a way that
lets you be more confident of its stability.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Type Inference&lt;/span&gt;

&lt;p&gt;
Consider the following code:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
x: int = 5
x = 'abc'
print(x)
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
This first defines the variable &lt;code&gt;x&lt;/code&gt;, giving it a type
annotation of &lt;code&gt;int&lt;/code&gt;.
It also assigns it to the integer 5. On the next line, it assigns
&lt;code&gt;x&lt;/code&gt; the
string &lt;code&gt;abc&lt;/code&gt;. And on the third line, it prints the value of
&lt;code&gt;x&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
The Python language itself has no problems with the above code. But if
you run &lt;code&gt;mypy&lt;/code&gt; against it, you'll get an error message:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
mytest.py:5: error: Incompatible types in assignment
   (expression has type "str", variable has type "int")
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
As the message says, the code declared the variable to have type
&lt;code&gt;int&lt;/code&gt;,
but then assigned a string to it. Mypy can figure this out because,
despite what many people believe, Python is a strongly typed language.
That is, every object has one clearly defined type. Mypy notices this
and then warns that the code is assigning values that are contrary to what
the declarations said.
&lt;/p&gt;

&lt;p&gt;
In the above code, you can see that I declared &lt;code&gt;x&lt;/code&gt; to be of
type &lt;code&gt;int&lt;/code&gt; at
definition time, but then assigned it to a string, and then I got an error.
What if I don't add the annotation at all? That is, what if I run the
following code via Mypy:

&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/pythons-mypy-advanced-usage" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Mon, 24 Jun 2019 11:30:00 +0000</pubDate>
    <dc:creator>Reuven M. Lerner</dc:creator>
    <guid isPermaLink="false">1340606 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Build Your Own Internet Radio Receiver</title>
  <link>https://www.linuxjournal.com/content/build-your-own-internet-radio-receiver</link>
  <description>  &lt;div data-history-node-id="1340545" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/nick-tufillaro" lang="" about="https://www.linuxjournal.com/users/nick-tufillaro" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Nick Tufillaro&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;Tune in to communities around the world with the push of a button.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
When I get home at night, I like to tune into the world with the push
of a button. I've lived in lots of different places—from Dunedin,
New Zealand, to Santa Fe, New Mexico—and in each town, I've come to love
a radio station (usually a community radio station) that embodies
the spirit of the place. With the push of a button, I can get a bit back
in sync with each of these places and also visit new communities, thanks
to internet radio.
&lt;/p&gt;

&lt;p&gt;
Why build your own internet radio receiver? One option, of course, is
simply to use an app for a receiver. However, I've found that the most common
apps don't keep their focus on the task at hand, and are increasingly
distracted by offering additional social-networking services. And besides,
I want to listen now. I don't want to check into my computer or phone,
log in yet again, and endure the stress of recalling YAPW (Yet Another
PassWord). I've also found that the current offering of internet radio
boxes falls short of my expectations. Like I said, I've lived in a lot
of places—more than two or four or eight. I want a lot of buttons, so I can
tune in to a radio station with just one gesture. Finally, I've noticed
that streams are increasingly problematic if I don't go directly to
the source. Often, streams chosen through a "middle man" start with
an ad or blurb that is tacked on as a preamble. Or sometimes the "middle man" might
tie me to a stream of lower audio quality than the best being served up.
&lt;/p&gt;

&lt;p&gt;
So, I turned to building my own internet radio receiver—one with lots
of buttons that allow me to "tune in" without being too pushy. In this
article,
I share my experience. In principle, it should be easy—you just need a Linux distro, a ship to sail her on and an external
key pad for a rudder. In practice, it's not too hard, but there are a
few obstacles along the course that I hope to help you navigate.
&lt;/p&gt;

&lt;p&gt;
My recipe list included the following:
&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;
A used notebook with an ultra low voltage
(Core 2 Duo) processor.&lt;/li&gt;

&lt;li&gt;
An audio interface with an optical TOSLINK.&lt;/li&gt;

&lt;li&gt;
pyradio: an open-source Python radio program.&lt;/li&gt;

&lt;li&gt;
An external keypad.&lt;/li&gt;&lt;/ol&gt;&lt;img src="https://www.linuxjournal.com/sites/default/files/styles/max_650x650/public/u%5Buid%5D/12693f1smaller.png" width="600" height="572" alt="""" class="image-max_650x650" /&gt;&lt;p&gt;
&lt;em&gt;Figure 1. My Hardware Setup&lt;/em&gt;
&lt;/p&gt;

&lt;p&gt;
Why a notebook and not a Raspberry Pi or ship of a similar ilk? Mostly
due to time—my time in particular. It's not too hard to find a high quality
notebook about ten years old for about $50, so the cost is really not
that different, and I find the development platform to be much
quicker.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/build-your-own-internet-radio-receiver" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Mon, 27 May 2019 11:00:00 +0000</pubDate>
    <dc:creator>Nick Tufillaro</dc:creator>
    <guid isPermaLink="false">1340545 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Introducing Mypy, an Experimental Optional Static Type Checker for Python</title>
  <link>https://www.linuxjournal.com/content/introducing-mypy-experimental-optional-static-type-checker-python</link>
  <description>  &lt;div data-history-node-id="1340583" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/reuven-m-lerner" lang="" about="https://www.linuxjournal.com/users/reuven-m-lerner" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Reuven M. Lerner&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;Tighten up your code and identify errors before they occur with
&lt;code&gt;mypy&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
I've been using dynamic languages—Perl, Ruby and Python—for
many years. I love the flexibility and expressiveness that such
languages provide. For example, I can define a function that sums
numbers:

&lt;/p&gt;&lt;pre&gt;
&lt;code&gt;
def mysum(numbers):
    total = 0
   for one_number in numbers:
       total += one_number
   return total
&lt;/code&gt;
&lt;/pre&gt;


&lt;p&gt;
The above function will work on any iterable that returns numbers. So
I can run the above on a list, tuple or set of numbers. I can even
run it on a dictionary whose keys are all numbers. Pretty great,
right?
&lt;/p&gt;

&lt;p&gt;
Yes, but for my students who are used to static, compiled languages,
this is a very hard thing to get used to. After all, how can you make
sure that no one passes you a string, or a number of strings? What if
you get a list in which some, but not all, of the elements are numeric?
&lt;/p&gt;

&lt;p&gt;
For a number of years, I used to dismiss such worries. After all,
dynamic languages have been around for a long time, and they have done a good
job. And really, if people are having these sorts of type mismatch
errors, then maybe they should be paying closer attention. Plus, if you
have enough testing, you'll probably be fine.
&lt;/p&gt;

&lt;p&gt;
But as Python (and other dynamic languages) have been making inroads
into large companies, I've become increasingly convinced that there's
something to be said for type checking. In particular, the fact that
many newcomers to Python are working on large projects, in which many
parts need to interoperate, has made it clear to me that some sort of
type checking can be useful.
&lt;/p&gt;

&lt;p&gt;
How can you balance these needs? That is, how can you enjoy Python as a
dynamically typed language, while simultaneously getting some added
sense of static-typing stability?
&lt;/p&gt;

&lt;p&gt;
One of the most popular answers is a system known as &lt;code&gt;mypy&lt;/code&gt;, which
takes advantage of Python 3's type annotations for its own purposes.
Using &lt;code&gt;mypy&lt;/code&gt; means that you can write and run Python in the normal way,
gradually adding static type checking over time and checking it
outside your program's execution.
&lt;/p&gt;

&lt;p&gt;
In this article, I start exploring &lt;code&gt;mypy&lt;/code&gt; and how you can use it to
check for problems in your programs. I've been impressed by
&lt;code&gt;mypy&lt;/code&gt;,
and I believe you're likely to see it deployed in a growing number
of places, in no small part because it's optional, and thus allows
developers to use it to whatever degree they deem necessary,
tightening things up over time, as well.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Dynamic and Strong Typing&lt;/span&gt;

&lt;p&gt;
In Python, users enjoy not only dynamic typing, but also strong typing.
"Dynamic" means that variables don't have types, but that values do.
So you can say:

&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/introducing-mypy-experimental-optional-static-type-checker-python" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Mon, 13 May 2019 11:30:00 +0000</pubDate>
    <dc:creator>Reuven M. Lerner</dc:creator>
    <guid isPermaLink="false">1340583 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Become Queen Bee for a Day Using Python's Built-in Data Types</title>
  <link>https://www.linuxjournal.com/content/become-queen-bee-day-using-pythons-built-data-types</link>
  <description>  &lt;div data-history-node-id="1340458" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/reuven-m-lerner" lang="" about="https://www.linuxjournal.com/users/reuven-m-lerner" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Reuven M. Lerner&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;Cheaters never win, but at least they can use Python.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
Like many other nerds, I love word puzzles. I'm not always great
at them, and I don't always have time to do them, but when I do, I
really enjoy them.
&lt;/p&gt;

&lt;p&gt;
I recently discovered a new daily puzzle, known as "spelling bee",
that the &lt;em&gt;New York Times&lt;/em&gt; offers online. The idea is simple. There are
seven different letters, one in the center of a circle and six around
it. Your job is to make as many different words as you can from those
seven letters. Each word must be at least four letters long, and each
word also must contain the center letter. You can use each letter as many times
as you want.
&lt;/p&gt;

&lt;p&gt;
So if the letters are "eoncylt", with a center letter of "y", some
of the words you could create might be "cyclone", "eyelet" and "nylon".
&lt;/p&gt;

&lt;p&gt;
The online game gives you a score based on how many words you've
made from the potential pool. If you get them all, you're
awarded "queen bee" status.
&lt;/p&gt;
&lt;p&gt;
I do pretty well at this puzzle, but I've never managed to find all of
the hidden words. Nevertheless, I have become queen bee on a few
occasions. How? The answer is simple. I cheated. How? Using
Python, of course.
&lt;/p&gt;

&lt;p&gt;
Now, cheating at games isn't necessarily the first order of business
when it comes to programming. And cheating at word games in which
you're competing against yourself is probably a sign of unhealthy
competition. But, doing so also provides a great way to review some of the
ways you can use Python's built-in data types and the ease
with which you can process words and text.
&lt;/p&gt;

&lt;p&gt;
So in this article, I explore a number of ways you can cheat—and yes, become the queen bee, if only for a day.
&lt;/p&gt;

&lt;span class="h3-replacement"&gt;
Trying All Combinations&lt;/span&gt;

&lt;p&gt;
To start, you simply might try to form all of the possible
combinations you can with the letters you're given. As you might
remember from high-school math class, there's a difference between
"permutations" and "combinations". When you generate "permutations",
the order is important, but when you generate "combinations", the order
is not important.
&lt;/p&gt;

&lt;p&gt;
You easily can see this using Python's &lt;code&gt;itertools&lt;/code&gt; module, a part of
the standard library that has functions named &lt;code&gt;permutations&lt;/code&gt; and
&lt;code&gt;combinations&lt;/code&gt;. Each takes both an iterable data structure and the
number of items you want in each resulting list. For example:

&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/become-queen-bee-day-using-pythons-built-data-types" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Mon, 11 Mar 2019 11:30:00 +0000</pubDate>
    <dc:creator>Reuven M. Lerner</dc:creator>
    <guid isPermaLink="false">1340458 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>By Jupyter--Is This the Future of Open Science?</title>
  <link>https://www.linuxjournal.com/content/jupyter-future-open-science</link>
  <description>  &lt;div data-history-node-id="1340455" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/glyn-moody" lang="" about="https://www.linuxjournal.com/users/glyn-moody" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Glyn Moody&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;Taking the scientific paper to the next level.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
In a recent article, I explained why open source is &lt;a href="https://www.linuxjournal.com/content/open-science-means-open-source-or-least-it-should"&gt;a
vital part of open science&lt;/a&gt;. As I pointed out, alongside a massive
failure on the part of funding bodies to make open source a key aspect of
their strategies, there's also a similar lack of open-source engagement
with the needs and challenges of open science. There's not much that the
Free Software world can do to change the priorities of funders. But, a
lot can be done on the other side of things by writing good open-source
code that supports and enhances open science.
&lt;/p&gt;

&lt;p&gt;
People working in science potentially can benefit from every piece of
free software code—the operating systems and apps, and the tools and
libraries—so the better those become, the more useful they are
for scientists. But there's one open-source project in particular
that already has had a significant impact on how scientists work—&lt;a href="https://github.com/jupyter/design/wiki/Jupyter-Logo"&gt;Project
Jupyter&lt;/a&gt;:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;
Project Jupyter is a set of open-source software projects that
form the building blocks for interactive and exploratory computing that is
reproducible and multi-language. The main application offered by Jupyter
is the Jupyter Notebook, a web-based interactive computing platform
that allows users to author documents that combine live code, equations,
narrative text, interactive dashboard and other rich media.
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;
&lt;a href="https://jupyter.org/index.html"&gt;Project Jupyter&lt;/a&gt;
was spun-off from &lt;a href="https://ipython.org/"&gt;IPython&lt;/a&gt;
&lt;a href="https://speakerdeck.com/fperez/project-jupyter"&gt;in 2014 by
Fernando Pérez&lt;/a&gt;. Although it began as an environment for programming
Python, its ambitions have grown considerably. Today, dozens
of Jupyter kernels exist that allow other languages to be used. Indeed,
&lt;a href="https://jupyter.org/about"&gt;the project itself speaks&lt;/a&gt; of
supporting "interactive data science and scientific computing across
all programming languages". As well as this broad-based support for
programming languages, Jupyter is noteworthy for its power. It enables
users to create and share documents that contain live code, equations,
visualizations and narrative text. Uses include data cleaning and
transformation, numerical simulation, statistical modeling, data
visualization and machine learning.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/jupyter-future-open-science" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Mon, 04 Mar 2019 12:30:00 +0000</pubDate>
    <dc:creator>Glyn Moody</dc:creator>
    <guid isPermaLink="false">1340455 at https://www.linuxjournal.com</guid>
    </item>

  </channel>
</rss>
