Planet Python

Subscribe to Planet Python feed
Planet Python - http://planetpython.org/
Updated: 18 hours 27 min ago

Test and Code: 102: Cosmic Python, TDD, testing and external dependencies - Harry Percival

Thu, 2020-02-27 04:00

Harry Percival has completed his second book, "Architecture Patterns with Python".
So of course we talk about the book, also known as "Cosmic Python".
We also discuss lots of testing topics, especially related to larger systems and systems involving third party interfaces and APIs.

Topics

  • Harry's new book, "Architecture Patterns with Python". a.k.a. Cosmic Python
  • TDD : Test Driven Development
  • Test Pyramid
  • Tradeoffs of different architectural choices
  • Mocks and their pitfalls
  • Avoiding mocks
  • Separating conceptual business logic
  • Dependency injection
  • Dependency inversion
  • Identifying external dependencies
  • Interface adapters to mimize the exposed surface area of external dependencies
  • London School vs Classic/Detroit School of TDD
  • Testing strategies for testing external REST APIs

Special Guest: Harry Percival.

Sponsored By:

Support Test & Code: Python Software Testing & Engineering

Links:

<p>Harry Percival has completed his second book, &quot;Architecture Patterns with Python&quot;.<br> So of course we talk about the book, also known as &quot;Cosmic Python&quot;.<br> We also discuss lots of testing topics, especially related to larger systems and systems involving third party interfaces and APIs.</p> <p>Topics </p> <ul> <li>Harry&#39;s new book, &quot;Architecture Patterns with Python&quot;. a.k.a. Cosmic Python </li> <li>TDD : Test Driven Development</li> <li>Test Pyramid</li> <li>Tradeoffs of different architectural choices</li> <li>Mocks and their pitfalls</li> <li>Avoiding mocks</li> <li>Separating conceptual business logic</li> <li>Dependency injection</li> <li>Dependency inversion</li> <li>Identifying external dependencies</li> <li>Interface adapters to mimize the exposed surface area of external dependencies</li> <li>London School vs Classic/Detroit School of TDD</li> <li>Testing strategies for testing external REST APIs</li> </ul><p>Special Guest: Harry Percival.</p><p>Sponsored By:</p><ul><li><a href="https://oxylabs.io/testandcode" rel="nofollow">Oxylabs</a>: <a href="https://oxylabs.io/testandcode" rel="nofollow">Visit oxylabs.io/testandcode to find out more about their services and to apply for a free trial of their Next-Generation Residential Proxies.</a></li></ul><p><a href="https://www.patreon.com/testpodcast" rel="payment">Support Test & Code: Python Software Testing & Engineering</a></p><p>Links:</p><ul><li><a href="https://www.cosmicpython.com/" title="Cosmic Python - Simple Patterns for Building Complex Applications" rel="nofollow">Cosmic Python - Simple Patterns for Building Complex Applications</a></li><li><a href="https://amzn.to/39fZbve" title="Architecture Patterns with Python - on Amazon" rel="nofollow">Architecture Patterns with Python - on Amazon</a></li><li><a href="https://twitter.com/hjwp/" title="Harry Percival (@hjwp) / Twitter" rel="nofollow">Harry Percival (@hjwp) / Twitter</a></li><li><a href="https://twitter.com/bob_the_mighty" title="Bob Gregory (@bob_the_mighty) / Twitter" rel="nofollow">Bob Gregory (@bob_the_mighty) / Twitter</a></li><li><a href="https://pypi.org/project/vcrpy/" title="vcrpy · PyPI" rel="nofollow">vcrpy · PyPI</a></li><li><a href="https://www.cosmicpython.com/blog/2020-01-25-testing_external_api_calls.html" title="Writing tests for external API calls" rel="nofollow">Writing tests for external API calls</a></li><li><a href="https://us.pycon.org/2020/schedule/presentation/118/" title="Stop Using Mocks (for a while) - Harry's PyCon talk" rel="nofollow">Stop Using Mocks (for a while) - Harry's PyCon talk</a></li></ul>
Categories: FLOSS Project Planets

Roberto Alsina: Python Meetup Buenos Aires 27/2/2020

Wed, 2020-02-26 19:02

Charla en el Buenos Aires Python Meetup el 7/11/2019

Algunos tips y comentarios sarcásticos para hacer que tu código Python sea más parecido a Python y menos parecido a otra cosa.

Categories: FLOSS Project Planets

Reuven Lerner: Want to spend more time coding Python, and less time on Stack Overflow?

Wed, 2020-02-26 11:58

How many times a day do you visit Stack Overflow?  (If you’re like most programmers, the answer is “many.”)  Wouldn’t it be nice to just be able to write Python code, without interrupting your work every few hours to check (or double-check) something?

After all, whether you’re a data scientist, app developer, or just a hobbyist, your goal isn’t to search for answers to your problems. Your goal is to actually solve those problems.

Consider what would happen if you were able to use all of that search-for-answers time on actually solving problems:

  • You wouldn’t have to read bad and semi-bad answers before (finally) finding the right solution.
  • You wouldn’t have to mess with the answer you found, to make it appropriate for your situation.
  • You could take on bigger and more complex projects, because you’d be able to concentrate on the higher-level ideas and problems, doing the simpler stuff easily and quickly.
  • You would write shorter and more expressive code, impressing others and making future maintenance easier.
  • You would be able to delight your clients with faster turnaround time and more sophisticated solutions.

People are using Python for all sorts of amazing things nowadays. But you’re only able to do those amazing things when you’re solving problems, not when you’re dealing with the nuts and bolts, or searching for answers online:

  • Become a data scientist, contributing to everything from drug discovery to financial models to self-driving cars. (As you might know, Python is the leading language in data science and machine learning — so knowing it is the key to getting a job in this hot industry.)
  • Create Web applications, using Python-based frameworks such as Django and Flask, to create sites like Instagram, Pinterest, and Dropbox.
  • Automate your home or office on a Raspberry Pi, integrating systems such as temperature sensors to microcontrollers in a single program.
  • Use a single language to automate everything on your computer, instead of using such domain-specific languages as VBA and bash.

On March 10th, I’m starting a cohort of Weekly Python Exercise, my 15-week course specifically designed to improve your Python fluency.   (This is cohort B1, one of three advanced cohorts I offer each year.)

This cohort is aimed at anyone with at least 6-8 months of Python under their belt, who wants to go beyond basic data structures, function definitions, and objects — learning about and getting better at such topics as:

  • iterators
  • generators
  • decorators
  • advanced object-oriented techniques
  • threads and processes
Learn more, get a WPE trial, and sign up for Weekly Python Exercise B1

Questions or comments? Just contact me via e-mail (reuven@lerner.co.il) or on Twitter (@reuvenmlerner)

The post Want to spend more time coding Python, and less time on Stack Overflow? appeared first on Reuven Lerner.

Categories: FLOSS Project Planets

EuroPython: EuroPython 2020: Call for Proposals opens on March 9th

Wed, 2020-02-26 11:45

We are happy to announce that the Call for Proposals will open on March 9. It will be left open for three weeks and then close on:

Sunday, March 29 23:59:59 CEST

While you wait for submissions to open, please check out the Call for Proposals details on our pre-launch website:

https://ep2020.europython.eu/call-for-proposals/

We’re looking for proposals on every aspect of Python: all levels of programming from novice to advanced, applications, frameworks, data science, Python projects, internals or topics which you’re excited about, your experiences with Python and its ecosystem, creative or artistic things you’ve done with Python, to name a few.

EuroPython is a community conference and we are eager to hear about your use of Python.

Since feedback shows that our audience is very interested in advanced topics, we’d appreciate more entries in this category for EuroPython 2020.

Please help spread word about Call for Proposals to anyone who might be interested. Thanks.

Enjoy,

EuroPython 2020 Team
https://ep2020.europython.eu/

Categories: FLOSS Project Planets

PyCharm: Webinar Recording: “Security Checks for Python Code” with Anthony Shaw

Wed, 2020-02-26 11:24

Last week we had a webinar on Python security with Anthony Shaw. He covered a number of places where Python code, including popular frameworks, run into security vulnerabilities. He also showed his PyCharm plugin for showing and fixing known vulnerabilities. The webinar recording is now available.

So much covered in this webinar! Anthony discussed common Python security vulnerabilities, how his plugin helps, how to run it in continuous integration, and more.

Timeline
  • 00:30: Demo the application being used
  • 01:30: Installing the plugin
  • 03:49: Show some reported vulnerabilities
  • 04:28: Running the checks manually
  • 05:15: First round of questions
  • 11:20: Investigate first vulnerability
  • 15:30: Second round of questions
  • 16:20: Browsing the shipped list of inspections/vulnerabilities
  • 20:58: Code inspection tool
  • 26:58: Third round of questions
  • 30:38: Django-specific app vulnerability
  • 36:35: Show documentation page with full list of vulnerabilities
  • 38:28: Fourth round of questions
  • 44:07: Running checks in continuous integration (CI) via Docker image, headless PyCharm
  • 47:07: Final round of questions
  • 51:18: Suppressing warnings on a specific line
  • 52:21: “View on Marketplace” for the GitHub Action
Categories: FLOSS Project Planets

Real Python: The Beginner's Guide to Python Turtle

Wed, 2020-02-26 09:00

When I was a kid, I used to learn Logo, a programming language that involved a turtle that you could move around the screen with just a few commands. I remember feeling like a computer genius as I controlled this little object on my screen, and this was what got me interested in programming in the first place. The Python turtle library comes with a similar interactive feature that gives new programmers a taste of what it’s like to work with Python.

In this tutorial, you will:

  • Understand what the Python turtle library is
  • Learn how to set turtle up on your computer
  • Program with the Python turtle library
  • Grasp some important Python concepts and turtle commands
  • Develop a short but entertaining game using what you’ve learned

If you’re a beginner to Python, then this tutorial will help you as you take your first steps into the world of programming with the help of the Python turtle library!

Free Bonus: Click here to get a Python Cheat Sheet and learn the basics of Python 3, like working with data types, dictionaries, lists, and Python functions.

Getting to Know the Python turtle Library

turtle is a pre-installed Python library that enables users to create pictures and shapes by providing them with a virtual canvas. The onscreen pen that you use for drawing is called the turtle and this is what gives the library its name. In short, the Python turtle library helps new programmers get a feel for what programming with Python is like in a fun and interactive way.

turtle is mainly used to introduce children to the world of computers. It’s a straightforward yet versatile way to understand the concepts of Python. This makes it a great avenue for kids to take their first steps in Python programming. That being said, the Python turtle library is not restricted to little ones alone! It’s also proved extremely useful for adults who are trying their hands at Python, which makes it great for Python beginners.

With the Python turtle library, you can draw and create various types of shapes and images. Here’s a sample of the kinds of drawings you can make with turtle:

Cool, right? This is just one of many different drawings you can make using the Python turtle library. Most developers use turtle to draw shapes, create designs, and make images. Others use turtle to create mini-games and animations, just like the one you saw above.

Getting Started With turtle

Before you continue, there are two important things that you’ll need to do to make the most of this tutorial:

  1. Python Environment: Make sure that you’re familiar with your programming environment. You can use applications like IDLE or Jupyter Notebook to program with turtle. However, if you’re not comfortable with them, then you can program with the REPL, which you’ll use in this tutorial.

  2. Python Version: Ensure that you have version 3 of Python on your computer. If not, then you can download it from the Python website. For help setting things up, check out Python 3 Installation & Setup Guide.

The good thing about turtle is that it’s a built-in library, so you don’t need to install any new packages. All you need to do is import the library into your Python environment, which in this case would be the REPL. Once you open your REPL application, you can run Python 3 on it by typing the following line of code:

>>>>>> python3

This calls Python 3 into your REPL application and opens up the environment for you.

Before you begin your Python programming, you need to understand what a library is. In the non-computer world, a library is a place where different types of books are stored. You can access these books at any time, take whatever information you need from them, and return them to the same place.

In the computer world, a library works similarly. By definition, a library is a set of important functions and methods that you can access to make your programming easier. The Python turtle library contains all the methods and functions that you’ll need to create your images. To access a Python library, you need to import it into your Python environment, like this:

>>>>>> import turtle

Now that you have turtle in your Python environment, you can begin programming with it. turtle is a graphical library, which means you’ll need to create a separate window (called the screen) to carry out each drawing command. You can create this screen by initializing a variable for it.

In Python, you use variables to store information that you’ll use later on in your program. You initialize a variable when you assign a starting value to it. Since the value of the variable isn’t constant, it can change several times during the execution of your program.

Now, to open the turtle screen, you initialize a variable for it in the following way:

>>>>>> s = turtle.getscreen()

You should see a separate window open up:

This window is called the screen. It’s where you can view the output of your code. The little black triangular shape in the middle of the screen is called the turtle.

Note: Keep in mind that when you name a variable, you need to pick a name that can be easily understood by anyone who’s looking at your program. However, you must also choose a name that’s convenient for you to use, especially because you’ll be calling it very often throughout your program!

For example, choosing a name like my_turtle_screen_name would be tedious to keep typing, while a name like Joe or a would appear to be very random. Using a single alphabet character, like s in this case, would be much more suitable. That’s because it’s short and sweet, and it’s clear to remember that the letter s refers to the screen.

Next, you initialize the variable t, which you’ll then use throughout the program to refer to the turtle:

>>>>>> t = turtle.Turtle()

Just like for the screen, you can also give this variable another name like a or Jane or even my_turtle, but in this case, you’ll stick with t.

You now have your screen and your turtle. The screen acts as a canvas, while the turtle acts like a pen. You can program the turtle to move around the screen. The turtle has certain changeable characteristics, like size, color, and speed. It always points in a specific direction, and will move in that direction unless you tell it otherwise:

  • When it’s up, it means that no line will be drawn when it moves.
  • When it’s down, it means that a line will be drawn when it moves.

In the next section, you’ll explore the different ways of programming with the Python turtle library.

Programming With turtle

The first thing you’ll learn when it comes to programming with the Python turtle library is how to make the turtle move in the direction you want it to go. Next, you’ll learn how to customize your turtle and its environment. Finally, you’ll learn a couple of extra commands with which you can perform some special tasks.

Moving the Turtle

There are four directions that a turtle can move in:

  • Forward
  • Backward
  • Left
  • Right

The turtle moves .forward() or .backward() in the direction that it’s facing. You can change this direction by turning it .left() or .right() by a certain degree. You can try each of these commands like so:

>>>>>> t.right(90) >>> t.forward(100) >>> t.left(90) >>> t.backward(100)

When you run these commands, the turtle will turn right by ninety degrees, go forward by a hundred units, turn left by ninety degrees, and move backward by a hundred units. You can see how this looks in the image below:

You can use the shortened versions of these commands as well:

  • t.rt() instead of t.right()
  • t.fd() instead of t.forward()
  • t.lt() instead of t.left()
  • t.bk() instead of t.backward()

You can also draw a line from your current position to any other arbitrary position on the screen. This is done with the help of coordinates:

The screen is divided into four quadrants. The point where the turtle is initially positioned at the beginning of your program is (0,0). This is called Home. To move the turtle to any other area on the screen, you use .goto() and enter the coordinates like this:

>>>>>> t.goto(100,100)

Your output will look like this:

You’ve drawn a line from your current position to the point (100,100) on the screen.

To bring the turtle back to its home position, you type the following:

>>>>>> t.home()

This is like a shortcut command that sends the turtle back to the point (0,0). It’s quicker than typing t.goto(0,0).

Drawing a Shape

Now that you know the movements of the turtle, you can move on to making actual shapes. You can start by drawing polygons since they all consist of straight lines connected at certain angles. Here’s an example that you can try:

>>>>>> t.fd(100) >>> t.rt(90) >>> t.fd(100) >>> t.rt(90) >>> t.fd(100) >>> t.rt(90) >>> t.fd(100)

Your output will look like this:

Well done! You’ve just drawn a square. In this way, the turtle can be programmed to create different shapes and images.

Now, try drawing a rectangle, using this code as a template. Remember, in a rectangle, all four sides are not equal. You’ll need to change the code accordingly. Once you do that, you can even try creating other polygons by increasing the number of sides and changing the angles.

Drawing Preset Figures

Suppose you want to draw a circle. If you attempt to draw it in the same way as you drew the square, then it would be extremely tedious, and you’d have to spend a lot of time just for that one shape. Thankfully, the Python turtle library provides a solution for this. You can use a single command to draw a circle:

>>>>>> t.circle(60)

You’ll get an output like this:

The number within the brackets is the radius of the circle. You can increase or decrease the size of the circle by changing the value of its radius.

In the same way, you can also draw a dot, which is nothing but a filled-in circle. Type in this command:

>>>>>> t.dot(20)

You’ll get a filled-in circle like this:

The number within the brackets is the diameter of the dot. Just like with the circle, you can increase or decrease the size of the dot by changing the value of its diameter.

Great job so far! You’ve learned how to move the turtle around and create different shapes with it. In the next few sections, you’ll see how you can customize your turtle and its environment, based on your requirements.

Changing the Screen Color

By default, turtle always opens up a screen with a white background. However, you can change the color of the screen at any time using the following command:

>>>>>> turtle.bgcolor("blue")

You can replace "blue" with any other color. Try "green" or "red". You’ll get a result like this:

You can use a variety of colors for your screen just by typing in their hex code number. To learn more about using different colors, check out the Python turtle library documentation.

Changing the Screen Title

Sometimes, you may want to change the title of your screen. You can make it more personal, like "My Turtle Program", or more suitable to what you’re working on, like "Drawing Shapes With Turtle". You can change the title of your screen with the help of this command:

>>>>>> turtle.title("My Turtle Program")

Your title bar will now display this:

In this way, you can change the heading of your screen according to your preference.

Changing the Turtle Size

You can increase or decrease the size of the onscreen turtle to make it bigger or smaller. This changes only the size of the shape without affecting the output of the pen as it draws on the screen. Try typing in the following commands:

>>>>>> t.shapesize(1,5,10) >>> t.shapesize(10,5,1) >>> t.shapesize(1,10,5) >>> t.shapesize(10,1,5)

Your outputs will look like this:

The numbers given are the parameters for the size of the turtle:

  • Stretch length
  • Stretch width
  • Outline width

You can change these according to your preference. In the example given above, you can see a visible difference in the appearance of the turtle. For more information on how you can change the size of the turtle, check out the Python turtle library documentation.

Changing the Pen Size

The previous command changed the size of the turtle’s shape only. However, sometimes, you may need to increase or decrease the thickness of your pen. You can do this using the following command:

>>>>>> t.pensize(5) >>> t.forward(100)

This results in an outcome like this:

As you can see, the size of your pen is now five times the original size (which was one). Try drawing some more lines of various sizes, and compare the difference in thickness between them.

Changing the Turtle and Pen Color

When you first open a new screen, the turtle starts out as a black figure and draws with black ink. Based on your requirements, you can do two things:

  • Change the color of the turtle: This changes the fill color.
  • Change the color of the pen: This changes the outline or the ink color.

You can even choose both of these if you wish. Before you change the colors, increase the size of your turtle to help you see the color difference more clearly. Type in this code:

>>>>>> t.shapesize(3,3,3)

Now, to change the color of the turtle (or the fill), you type the following:

>>>>>> t.fillcolor("red")

Your turtle will look like this:

To change the color of the pen (or the outline), you type the following:

>>>>>> t.pencolor("green")

Your turtle will look like this:

To change the color of both, you type the following:

>>>>>> t.color("green", "red")

Your turtle will look like this:

Here, the first color is for the pen, and the second is for the fill. Note that changing the color of the pen and the fill also changes the color of the onscreen turtle accordingly.

Filling in an Image

Coloring in an image usually makes it look better, doesn’t it? The Python turtle library gives you the option to add color to your drawings. Try typing in the following code and see what happens:

>>>>>> t.begin_fill() >>> t.fd(100) >>> t.lt(120) >>> t.fd(100) >>> t.lt(120) >>> t.fd(100) >>> t.end_fill()

When you execute this code, you’ll get a triangle that’s filled in with a solid color, like this:

When you use .beginfill(), you’re telling your program that you’re going to be drawing a closed shape which will need to be filled in. Then, you use .endfill() to indicate that you’re done creating your shape and it can now be filled in.

Changing the Turtle Shape

The initial shape of the turtle isn’t really a turtle, but a triangular figure. However, you can change the way the turtle looks, and you do have a couple of options when it comes to doing so. You can have a look at some of them by typing in the following commands:

>>>>>> t.shape("turtle") >>> t.shape("arrow") >>> t.shape("circle")

The shape of the turtle will change accordingly, like this:

You have a couple of other options that you can try as well:

  • Square
  • Arrow
  • Circle
  • Turtle
  • Triangle
  • Classic

The classic shape is the original shape. Check out the Python turtle library documentation to learn more about the types of shapes that you can use.

Changing the Pen Speed

The turtle generally moves at a moderate pace. If you want to decrease or increase the speed to make your turtle move slower or faster, then you can do so by typing the following:

>>>>>> t.speed(1) >>> t.forward(100) >>> t.speed(10) >>> t.forward(100)

This code will first decrease the speed and move the turtle forward, then increase the speed and move the turtle forward again, like this:

The speed can be any number ranging from 0 (the slowest speed) to 10 (the highest speed). You can play around with your code to see how fast or slow the turtle will go.

Customizing in One Line

Suppose you want to set your turtle’s characteristics to the following:

  • Pen color: purple
  • Fill color: orange
  • Pen size: 10
  • Pen speed: 9

From what you’ve just learned, the code should look something like this:

>>>>>> t.pencolor("purple") >>> t.fillcolor("orange") >>> t.pensize(10) >>> t.speed(9) >>> t.begin_fill() >>> t.circle(90) >>> t.end_fill()

It’s pretty long, but not that bad, right?

Now, just imagine if you had ten different turtles. Changing all of their characteristics would be extremely tiresome for you to do! The good news is that you can reduce your workload by altering the parameters in just a single line of code, like this:

>>>>>> t.pen(pencolor="purple", fillcolor="orange", pensize=10, speed=9) >>> t.begin_fill() >>> t.circle(90) >>> t.end_fill()

This will give you a result like this:

This single line of code changed the entire pen, without you having to change each characteristic individually. To learn more about this command, check out the Python turtle library documentation.

Great job! Now that you’ve learned to customize your turtle and the screen, take a look at some other important commands that are required while drawing with the Python turtle library.

Picking the Pen Up and Down

Sometimes, you may want to move your turtle to another point on the screen without drawing anything on the screen itself. To do this, you use .penup(). Then, when you want to start drawing again, you use .pendown(). Give it a shot using the code that you used previously to draw a square. Try typing the following code:

>>>>>> t.fd(100) >>> t.rt(90) >>> t.penup() >>> t.fd(100) >>> t.rt(90) >>> t.pendown() >>> t.fd(100) >>> t.rt(90) >>> t.penup() >>> t.fd(100) >>> t.pendown()

When you run this code, your output will look like this:

Here, you’ve obtained two parallel lines instead of a square by adding some extra commands in between the original program.

Undoing Changes

No matter how careful you are, there’s always a possibility of making a mistake. Don’t worry, though! The Python turtle library gives you the option to undo what you’ve done. If you want to undo the very last thing you did, then type in the following:

>>>>>> t.undo()

This undoes the last command that you ran. If you want to undo your last three commands, then you would type t.undo() three times.

Clearing the Screen

Right now, you probably have a lot on your screen since you’ve started this tutorial. To make room for more, just type in the following command:

>>>>>> t.clear()

This will clean up your screen so that you can continue drawing. Note here that your variables will not change, and the turtle will remain in the same position. If you have other turtles on your screen other than the original turtle, then their drawings will not be cleared out unless you specifically call them out in your code.

Resetting the Environment

You also have the option to start on a clean slate with a reset command. The screen will get cleared up, and the turtle’s settings will all be restored to their default parameters. All you need to to do is type in the following command:

>>>>>> t.reset()

This clears the screen and takes the turtle back to its home position. Your default settings, like the turtle’s size, shape, color, and other features, will also be restored.

Now that you’ve learned the fundamentals of programming with the Python turtle library, you’ll check out some bonus features that you may want to use while programming.

Leaving a Stamp

You have the option of leaving a stamp of your turtle on the screen, which is nothing but an imprint of the turtle. Try typing in this code to see how it works:

>>>>>> t.stamp() 8 >>> t.fd(100) >>> t.stamp() 9 >>> t.fd(100)

Your output will look like this:

The numbers that appear are the turtle’s location or stamp ID. Now, if you want to remove a particular stamp, then just use the following:

>>>>>> t.clearstamp(8)

This will clear the one with the stamp ID of 8.

Cloning Your Turtle

Sometimes, you may need to have more than one turtle on your screen. You’ll see an example of this later on in the final project. For now, you can get another turtle by cloning your current turtle into your environment. Try running this code to create a clone turtle, c, and then move both the turtles on the screen:

>>>>>> c = t.clone() >>> t.color("magenta") >>> c.color("red") >>> t.circle(100) >>> c.circle(60)

The output will look like this:

Awesome!

Now that you have an idea of some important commands from the Python turtle library, you’re ready to move on to a few more concepts that you’ll need to understand. These concepts are very much needed when it comes to programming in any language.

Using Loops and Conditional Statements

When you get into higher-level programming, you’ll find yourself using loops and conditional statements very often. That’s why, in this section, you’ll be going through a couple of turtle programs that make use of these types of commands. This will give you a practical approach when it comes to understanding these concepts. Before you begin, however, here are three definitions for you to keep in mind:

  1. Loops are a set of instructions that are continuously repeated until a particular condition is satisfied.
  2. Conditional statements carry out a certain task based on a condition that’s satisfied.
  3. Indentations are used to define blocks of code, especially when using loops and conditional statements. In general, you create an indentation by tapping the Tab key on the keyboard.

Now, let’s go ahead and explore these commands!

for Loops

Do you remember the program that you used to create a square? You had to repeat the same line of code four times, like this:

>>>>>> t.fd(100) >>> t.rt(90) >>> t.fd(100) >>> t.rt(90) >>> t.fd(100) >>> t.rt(90) >>> t.fd(100) >>> t.rt(90)

A much shorter way to do this is with the help of a for loop. Try running this code:

>>>>>> for i in range(4): ... t.fd(100) ... t.rt(90)

Here, the i is like a counter that starts from zero and keeps increasing by 1. When you say in range(4), you’re telling the program that the value of this i should be less than 4. It will terminate the program before i reaches 4.

Here’s a breakdown of how the program works:

  1. At i = 0, the turtle moves forward by 100 units and then turns 90 degrees to the right.
  2. At i = 0 + 1 = 1, the turtle moves forward by 100 units and then turns 90 degrees to the right.
  3. At i = 1 + 1 = 2, the turtle moves forward by 100 units and then turns 90 degrees to the right.
  4. At i = 2 + 1 = 3, the turtle moves forward by 100 units and then turns 90 degrees to the right.

The turtle will then exit the loop. To check the value of i, type i and then press the Enter key. You’ll get the value of i equal to 3:

>>>>>> i 3

Note that the whitespace that comes before line 2 and line 3 in the program is the indentation. This indicates that all 3 lines form a single block of code. To learn more about for loops in Python, check out Python “for” Loops (Definite Iteration).

while Loops

The while loop is used to perform a certain task while a condition is still satisfied. If the condition is no longer satisfied, then your code will terminate the process. You can use a while loop to create a series of circles by typing in this code:

>>>>>> n=10 >>> while n <= 40: ... t.circle(n) ... n = n+10

When you run this code, you’ll see the circles appearing one after the other, and each new circle will be larger than the previous one:

Here, n is used as a counter. You’ll need to specify by how much you want the value of n to increase in each loop. Take a look at this mini walk-through to see how the program works:

  1. At n = 10, the turtle draws a circle with a radius of 10 units. After that, the value of n is increased by 10.
  2. At n = 20, the turtle draws a circle with a radius of 20 units. Once again, the value of n is increased by 10.
  3. At n = 30, the turtle draws a circle with a radius of 30 units. For the third time, the value of n is increased by 10.
  4. At n = 40, the turtle draws a circle with a radius of 40 units. For the last time, the value of n is increased by 10.
  5. At n = 50, n is no longer less than or equal to 40. The loop is terminated.

To read more about while loops, check out Python “while” Loops (Indefinite Iteration).

Conditional Statements

You use conditional statements to check if a given condition is true. If it is, then the corresponding command is executed. Try typing in this program:

>>>>>> u = input("Would you like me to draw a shape? Type yes or no: ") >>> if u == "yes": ... t.circle(50)

input() is used to obtain input from the user. Here, it will store the user’s response under the variable u. Next, it will compare the value of u with the condition provided and check whether the value of u is "yes". If it’s "yes", then your program draws a circle. If the user types in anything else, then the program won’t do anything.

Note: The comparison operator == indicates a comparison. It’s used to check if the value of something is equal to something else. The assignment operator = is used to assign a value to something. To learn more about the differences between the two, check out Operators and Expressions in Python.

When you add an else clause to an if statement, you can specify two results based on whether the condition is true or false. Let’s see this in a program:

>>>>>> u = input("Would you like me to draw a shape? Type yes or no: ") >>> if u == "yes": ... t.circle(50) >>> else: ... print("Okay")

Here, you tell the program to display a particular output even when the user does not say "yes". You use print() to display some pre-defined characters on the screen.

Note that the user doesn’t need to type "no". They can type anything else, in which case, the result will always be "Okay", because you’re not explicitly telling the program that the user needs to type "no". Not to worry, however, as that can be fixed. You can add an elif clause to provide the program with several conditions and their respective outputs, as you can observe here:

>>>>>> u = input("Would you like me to draw a shape? Type yes or no: ") >>> if u == "yes": ... t.circle(50) >>> elif u == "no": ... print("Okay") >>> else: ... print("Invalid Reply")

As you can see, this program now has more than one outcome, depending on the input it receives. Here’s how this code works:

  • If you type in "yes", then the code processes the input and draws a circle, as per your instructions.
  • If you type in "no", then the code prints out "Okay" and your program is terminated.
  • If you type in anything else, like "Hello" or "Sandwich", then the code prints "Invalid Reply" and your program is terminated.

Note that this program is case-sensitive, so when you’re trying it out, be sure to put the strings in upper-case or lower-case accordingly.

To learn more about conditional statements, check out Conditional Statements in Python.

Final Project: The Python Turtle Race

So far, you’ve learned how to customize your turtle environment, program your turtle to move around the screen, and use loops and conditional statements to improve your code. Now it’s time for the most important part of your programming journey. In this section, you’ll be implementing all that you’ve learned into a single program by creating a fun game that you can play with your friends.

Before you begin, here’s what you need to know about the game:

  1. The Objective: The player whose turtle reaches its home first wins the game.

  2. How to Play:

    • Each player rolls a dice to get a number.
    • The player then moves their turtle by that many steps.
    • The players alternate turns until one of them wins.
  3. The Structure:

    • Each player had a turtle indicated by a different color. You can have more than two players, but for the sake of this tutorial, you’ll be creating a two-player game.
    • Each turtle has a home position that it must reach.
    • Each player uses a die to choose a value at random for their turn. In your program, the die is represented by a list of numbers from 1 to 6.

Now that you’ve understood the logic of the game, you can go ahead and begin creating it! First, you’ll need to set up the environment.

Setting Up the Game Environment

Start by importing the Python turtle library. After this, import the built-in random library, which you’ll use randomly select an item from a list:

>>>>>> import turtle >>> import random

Once these libraries are successfully called into your environment, you can proceed with the rest of your program.

Setting Up the Turtles and Homes

You now have to create the two turtles that will represent the players. Each turtle will be a different color, corresponding to the different players. Here, player one is green and player two is blue:

>>>>>> player_one = turtle.Turtle() >>> player_one.color("green") >>> player_one.shape("turtle") >>> player_one.penup() >>> player_one.goto(-200,100) >>> player_two = player_one.clone() >>> player_two.color("blue") >>> player_two.penup() >>> player_two.goto(-200,-100)

One you’ve created the turtles, you place them at their starting positions and make sure that these positions are aligned. Note that you created player two’s turtle by cloning player one’s turtle, changing its color, and placing it at a different starting point.

You now need to set up homes for the turtles. These homes will act as the finishing points for each turtle. Each of the turtles’ homes will be represented by a circle. Here, you need to make sure that both homes are equidistant from the starting point:

>>>>>> player_one.goto(300,60) >>> player_one.pendown() >>> player_one.circle(40) >>> player_one.penup() >>> player_one.goto(-200,100) >>> player_two.goto(300,-140) >>> player_two.pendown() >>> player_two.circle(40) >>> player_two.penup() >>> player_two.goto(-200,-100)

After drawing the respective homes, you send the turtles back to their starting positions:

Awesome! The visual aspects of your game are complete. You can now create the die that you’ll be using to play the game.

Creating the Die

You can create a virtual die for your game with a list, which is an ordered sequence of items. In real life, you might prepare grocery lists and to-do lists to help you stay organized. In Python, lists work in a similar way.

In this case, you’ll be using a list to create your die. First, you define your list of numbers in ascending order from 1 to 6. You can define a list by giving it a name and then enclosing its items within square brackets, like this:

>>>>>> die = [1,2,3,4,5,6]

This list has now become your die. To roll the dice, all you have to do is program your system to randomly select a number from it. The number that is selected will be considered as the output of the die.

Developing the Game

It’s time to develop the code for the rest of the game. You’ll be using loops and conditional statements here, so you need to be careful with the indentations and spaces. To start, take a look at the steps your program will need to take to run the game:

  1. Step 1: You’ll start by telling your program to check if either turtle has reached its home.
  2. Step 2: If they haven’t, then you’ll tell your program to allow the players to continue trying.
  3. Step 3: In each loop, you tell your program to roll the die by randomly picking a number from the list.
  4. Step 4: You then tell it to move the respective turtle accordingly, with the number of steps based on the outcome of this random selection.

The program keeps repeating this process, and stops once one of the turtles reaches the goal. Here’s how the code looks:

>>> 1 >>> for i in range(20): 2 ... if player_one.pos() >= (300,100): 3 ... print("Player One Wins!") 4 ... break 5 ... elif player_two.pos() >= (300,-100): 6 ... print("Player Two Wins!") 7 ... break 8 ... else: 9 ... player_one_turn = input("Press 'Enter' to roll the die ") 10 ... die_outcome = random.choice(die) 11 ... print("The result of the die roll is: ") 12 ... print(die_outcome) 13 ... print("The number of steps will be: ") 14 ... print(20*die_outcome) 15 ... player_one.fd(20*die_outcome) 16 ... player_two_turn = input("Press 'Enter' to roll the die ") 17 ... d = random.choice(die) 18 ... print("The result of the die roll is: ") 19 ... print(die_outcome) 20 ... print("The number of steps will be: ") 21 ... print(20*die_outcome) 22 ... player_two.fd(20*die_outcome)

Your final output will look a little something like this:

In summary, this is what the code is doing:

  1. Line 1 sets up a for loop with a range from 1 to 20.

  2. Lines 2 through 7 check if either player has reached their goal. If one of them has, then the program prints out the corresponding statement and breaks the loop.

  3. Line 8 moves the program on to the next set of steps if neither player has won.

  4. Line 9 prints out a statement asking player one to press the Enter key to roll the die.

  5. Line 10 takes a random value from the list die and stores it in dice_outcome.

  6. Line 11 prints a statement prior to displaying the outcome of the dice roll.

  7. Line 12 prints the dice outcome.

  8. Line 14 multiplies this value by 20 to reduce the overall number of steps required to complete the game.

  9. Line 15 moves player one’s turtle forward by this number of steps.

  10. Lines 16 to 22 repeat these steps for player two.

The entire for loop is repeated until one of the player’s turtles reaches the final position.

Note: In Python, you use the asterisk (*) to indicate multiplication. This is known as an arithmetic operator. You can also use the plus sign (+) for addition, the minus sign (-) for subtraction, and a slash (/) for division. To learn more about arithmetic operators, check out the Arithmetic Operators section of Operators and Expressions in Python.

Remember, you can customize the game however you want, so go ahead and play around with it! You can add more turtles, change the colors, change the speed, or even create some obstacles to challenge your players. It’s all up to you as the developer of the game!

Conclusion

In this tutorial, you’ve learned how to program with the Python turtle library and grasped some very important programming concepts. You know how to deal with variable initialization, loops, conditional statements, indentations, lists, and operators. This is a great start for you, especially if you’re new to the Python programming language!

Now you can:

  • Set up the Python turtle library
  • Move your turtle around
  • Customize your turtle and its environment
  • Program your turtle
  • Use basic programming concepts
  • Create a game that you can play with friends

Now you’re ready to venture into some higher-level Python programming. To progress further in your Python journey, check out Introduction to Python and 11 Beginner Tips for Learning Python Programming. Just remember to work hard and keep practicing, and you’ll find that you’re a Python expert in no time!

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

Categories: FLOSS Project Planets

PyBites: How to Write a Guest Article for PyBites

Wed, 2020-02-26 02:21

Hello Everybody! In this article I'll run through the procedure of using git and github to submit a guest article to PyBites.

1. Forking the Repository

In order to get started, you have to create a fork of the original repository. A fork is a copy of a project to your own Github account.

This way, you can work on your own copy and ask the project maintainer to accept some modifications on your copy into the main repository.

Head over to the PyBites blog Github repo and look for the Fork icon in the top right, I've marked it in green:

Git will start creating the copy, and when it's done, you'll have your very own pybites.github.io-src fork!

2. Cloning your copy

Now that we have our running fork, we can clone this from our own Github account.

A clone is a local copy of a project from your Github to your local machine, where you can start editing!

3. Preparing for the future

While you are making your edits or adding your article, the maintainers, or other contributors may be doing the same! Git already knows of our origin, it knows where we cloned from.

We also need to tell it what our upstream is, where did we fork from? Which is where the maintainers will be adding updates.

In this case that's https://github.com/pybites/pybites.github.io-src

So now, if we want to get the maintainers latest modifications and add them to our own repository, we can first pull the upstream master branch, and then push it to our origin master branch!

4. Before making modifications

The Gittiquette says that you should make a branch before starting any modifications.

A branch is a copy of our local copy at a certain point in time that will go on to live it's on life, and eventually (hopefully) rejoin with it's master somewhere down the road.

You can either create a branch while checking it out, or you can create a branch, and later switch to it with checkout.

You might want to set your branch name to something that you can recognize. Some trees have a lot of branches!

I'm currently writing this "how to add guest articles", so I'll give mine an obvious name:

Branching is mainly important when you want to verify that your new modifications are not conflicting with any new changes in the upstream.

5. Writing your article

Post directory and style

Guest articles are stored in content, are written in markdown and usually start with guest-

I've added a template you can use here

It contains the structure of most articles and some basic markdown syntax as example, [here]'s another cheat sheet for if you want to do even more!

You can also look at the other articles as an example.

Adding images

If you have images you want to add (screenshots, infographics,...), you can add them under content/images/ and refer to them in your article like this:

![Image Alt Text](images/your-image.png)

A new guest!

If this is your first article, you should also add a small bio in content/pages/guests.md, right above the comment:

<!-- insert your new bio above this line -->

You can copy one from the guests file yourself, or use the template for the bio.

6. Adding and commiting your changes

Commit's are collections of small changes you have made. Adding your article could probably go in a single commit. You're going to tell git that you've changed or added a bunch of files first:

...and then you're gonna store these changes in a commit:

I still have some work to do, but when you're ready, you can push your modified branch back to the branch on it's origin you've created for the modifications:

And you're all set!

If you're logged in and you go to the upstream github page, you'll notice github automatically detects you've pushed a branch that was related to this project!

And you can create a pull request, which effectively asks the maintainer to pull the changes you've made into the master branch.

Now all you have to do is wait for someone to review your changes and if they are approved, your article will soon be ours to read on the PyBites blog!

--

Thanks for reading, I hope you enjoyed it as much as I enjoyed writing it. If you have any remarks or questions, you can likely find me on the Pybites Slack Channel as 'Jarvis'.

Keep calm and code in Python!

-- Cedric

Categories: FLOSS Project Planets

The No Title® Tech Blog: Book review - Machine Learning with Python for Everyone, By Mark E. Fenner

Tue, 2020-02-25 21:10

Machine learning, one of the hottest tech topics of today, is being used more and more. Sometimes as the best tool for the job, other times perhaps as a buzzword that is mainly used as a way to make a product look cooler. However, without knowing what ML is and how it works behind the scenes, it’s very easy to get lost. But this book does a great job in guiding you all the way up from very simple math concepts to some sophisticated machine learning techniques.

Categories: FLOSS Project Planets

Wing Tips: Using Anaconda Environments with Wing Python IDE

Tue, 2020-02-25 20:00

Wing version 7.2 has been released, and we've been looking at the new features in this version. So far we've covered reformatting with Black and YAPF, Wing 7.2's expanded support for virtualenv, and using python -m with Wing.

This time we'll take a look at what Wing 7.2 provides for people that are using Anaconda environments created with conda create as an alternative to virtualenv.

What Wing 7.2 Adds

Wing 7.2 supports creating new Wing projects that use an existing Anaconda environment, so that the environment is automatically activated whenever the project is open. Debug processes, unit tests, the integrated Python Shell, and OS Commands all run in the activated environment.

Wing 7.2 also added the ability to create and configure a new Anaconda environment while creating a new Wing project.

Using an Existing Anaconda Environment

Wing tries to discover existing Anaconda environments and lists them in the drop down menu next to the Activated Env option under Python Executable in Project Properties and the New Project dialog, which are both in the Project menu:

Selecting one of the listed Anaconda environments configures the project to automatically activate that environment whenever the project is open:

If Wing cannot find your Anaconda environment automatically, you can instead manually enter the command that activates it.

Creating New Projects

Wing can also create a new Anaconda environment at the same time that a new Wing project is created. This is done by selected New Project from the Project menu and choosing Create New Anaconda Environment as the project type:

Wing will create the new environment, install packages, and then configure and save a project file. You can immediately start working in your new environment, which Wing automatically activates for you whenever you have the project open.

That's all there is to it!

For some additional details, see Using Wing with Anaconda.



That's it for now! We'll be back soon with more Wing Tips for Wing Python IDE.

As always, please don't hesitate to email support@wingware.com if you run into problems or have any questions.

Categories: FLOSS Project Planets

Matt Layman: A Week At A Time - Building SaaS #46

Tue, 2020-02-25 19:00
In this episode, we worked on a weekly view for the Django app. We made navigation that would let users click from one week to the next, then fixed up the view to pull time from that particular week. The first thing that I did was focus on the UI required to navigate to a new weekly view in the app. We mocked out the UI and talked briefly about the flexbox layout that is available to modern browsers.
Categories: FLOSS Project Planets

Roberto Alsina: Episodio 24: I like Windows!

Tue, 2020-02-25 18:02

Me puse a hacer un window manager de juguete en Python. Lo basé en HackWM. Hack. Hacker. Carlín! Se llama carlin_wm y realmente no sirve para nada, excepto como experiencia educativa. O sea, es re útil... para mí!

Categories: FLOSS Project Planets

Codementor: Build Systems with Speed and Confidence by Closing the Loop First!

Tue, 2020-02-25 15:48
A completely finished “loop” is when you can provide the required input to your system, and it produces the desired output (or side effects, if that’s how you like it). The “Close the loop first” technique is about closing this loop as fast as possible by creating a barebones version of it first, providing all or some required inputs, and generating a partial form of the desired output. Once we have closed this barebones loop, we can then begin implementing behaviours from the inside out, so that with each new change our loop starts looking more like the actual system we want.
Categories: FLOSS Project Planets

Python Insider: Python 3.8.2 and 3.9.0a4 are now available

Tue, 2020-02-25 15:02
On behalf of the entire Python development community, and the currently serving Python release team in particular, I’m pleased to announce the release of two of the latest Python editions.

Python 3.8.2

Python 3.8.2 is the second maintenance release of Python 3.8 and contains two months worth of bug fixes. Detailed information about all changes made in 3.8.2 can be found in its change log. Note that compared to 3.8.1, version 3.8.2 also contains the changes introduced in 3.8.2rc1 and 3.8.2rc2.

The Python 3.8 series is the newest feature release of the Python language, and it contains many new features and optimizations. You can find Python 3.8.2 here:
https://www.python.org/downloads/release/python-382/

See the “What’s New in Python 3.8” document for more information about features included in the 3.8 series.

Maintenance releases for the 3.8 series will continue at regular bi-monthly intervals, with 3.8.3 planned for April 2020 (at the PyCon US sprints).

Python 3.9.0a4

An early developer preview of Python 3.9 is also ready:
https://www.python.org/downloads/release/python-390a4/

Python 3.9 is still in development. This releasee, 3.9.0a4 is the fourth of six planned alpha releases. Alpha releases are intended to make it easier to test the current state of new features and bug fixes and to test the release process. During the alpha phase, features may be added up until the start of the beta phase (2020-05-18) and, if necessary, may be modified or deleted up until the release candidate phase (2020-08-10). Please keep in mind that this is a preview release and its use is not recommended for production environments.

We hope you enjoy both!

Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation.
https://www.python.org/psf/

Your friendly release team,

Ned Deily
Steve Dower
Łukasz Langa
Categories: FLOSS Project Planets

PyCoder’s Weekly: Issue #409 (Feb. 25, 2020)

Tue, 2020-02-25 14:30

#409 – FEBRUARY 25, 2020
View in Browser »

Analysing NBA Assists: How to Visualize Hidden Relationships in Data With Python

Using basketball as the background setting, the author discusses several different strategies for uncovering relationships and producing beautiful visualizations with Python.
JP HWANG

PyCon US 2020 Packaging Summit: Registration and Topic Proposal

Registration is open for the PyCon US 2020 Packaging Summit. Topic proposals are also being accepted. Both registration and topic proposals close on March 7, 2020.
PYTHON.ORG

Python Developers Are in Demand on Vettery

Vettery is an online hiring marketplace that’s changing the way people hire and get hired. Ready for a bold career move? Make a free profile, name your salary, and connect with hiring managers from top employers today →
VETTERY sponsor

Django Security Vulnerability: CVE-2020-7471

Django 1.11 before 1.11.28, 2.2 before 2.2.10, and 3.0 before 3.0.3 allows SQL Injection if untrusted data is used as a StringAgg delimiter (e.g., in Django applications that offer downloads of data as a series of rows with a user-specified column delimiter).
MITRE.ORG

Working With PDFs in Python

In this step-by-step course, you’ll learn how to work with a PDF in Python. You’ll see how to extract metadata from preexisting PDF files. You’ll also learn how to merge, split, watermark, and rotate pages in PDFs using Python and the PyPDF2 library.
REAL PYTHON video

Python in Production

Hynek Schlawack feels that discussions of Python web applications in production are missing from Python conferences. He is offering to mentor people who are interested in proposing conference talks on the subject
HYNEK SCHLAWACK

Null in Python: Understanding Python’s NoneType Object

Learn about the NoneType object None, which acts as the “null” in Python. This object represents emptiness, and you can use it to mark default parameters and even show when you have no result.
REAL PYTHON

PEP 584 PR Merged (Dictionary Union)

This will add the following dictionary operations: dict1 | dict2 (copy + update) and dict1 |= dict2 (update). See PEP 584 for example use cases.
GITHUB.COM/PYTHON

Discussions Scene From Werner Herzog’s “Programming in Python” ;-)

“I see the lie in front of me – import time, and I am appalled – how can a machine offer such a promise, such a lie, the ability to import time as if it were a simple commodity. Once again, the vile snake has bitten me.”
TWITTER.COM/MVATTUONE

Python Jobs Senior Python/Django Software Engineer (London, UK)

Zego

Python Developer (Malta)

Gaming Innovation Group

Senior Python Software Engineer (London, UK)

Tessian

Senior Software Engineer Backend (Denver, CO)

CyberGRX

Senior Python Software Developer (Vancouver, BC, Canada)

AbCellera

More Python Jobs >>>

Articles & Tutorials Pycel: Compiling Excel Spreadsheets to Python and Making Pretty Pictures [2011]

Author describes how he compiled Excel spreadsheets with formulas into Python code in order to optimize the calculations and visualize results. Very interesting read!
DIRK GORISSEN

Better Python Tracebacks With Rich

“I’ve never found Python tracebacks to be a great debugging aid beyond telling me what the exception was, and where it occurred. In a recent update to Rich, I’ve tried to refresh the humble traceback to give enough context to diagnose errors before switching back to the editor.”
WILL MCGUGAN

Monitor Python Application Metrics and Distribute Traces in Real Time With Datadog APM

Datadog’s APM generates detailed flame graphs that will help your teams identify bottlenecks and latency. If an error is spotted, you can easily pivot to related logs and metrics in seconds to troubleshoot without switching tools or contexts. Visualize Python metrics end-to-end with a free trial →
DATADOG sponsor

Introduction to Python SQL Libraries

Learn how to connect to different database management systems by using various Python SQL libraries. You’ll interact with SQLite, MySQL, and PostgreSQL databases and perform common database queries using a Python application.
REAL PYTHON

A Brief Network Analysis of Symbolism in Blake’s Poetry

The author explains how she used the spaCy and NetworkX libraries to analyze William Blake’s 18th century poetry collection The Songs of Innocence and of Excellence.
MARTA PALANDRI

Python Packaging Metadata

“Since this topic keeps coming up, I’d like to briefly share my thoughts on Python package metadata because it’s – as always – more complex than it seems.”
HYNEK SCHLAWACK

How Python Became the Popular Choice

“With the popularity of Python with programmers still growing, we tried to understand how it became one of the most impactful languages in the world.”
JUN WU

How to Add a robots.txt to Your Django Site

robots.txt is a standard file to communicate to “robot” crawlers, such as Google’s Googlebot, which pages they should not crawl.
ADAM JOHNSON

Automate Your Dating Life With 100 Lines of Python

Author used a Python-based man-in-the-middle proxy to deconstruct network calls made by the Hinge app and then built a service to automatically “swipe right” on dating profiles.
ELI MERNIT

Learn Python for Data Science in 4 Weeks

Learn the foundational Python programming and statistics skills needed for a job in data science in as little as 4 weeks. Work 1:1 with a data science mentor to master the skills needed to get started in your journey to a data science role. Enroll in Springboard’s data science career track prep course today.
SPRINGBOARD sponsor

Managing Kindle Highlights With Python and GitHub

Author writes a Python script to build a GitHub repo for storing Kindle book highlights in an organized way.
DUARTE O.CARMO

How to Cheat at Unit Tests With Pytest and Black

Some tips for quickly writing rough initial implementations for test cases and then iterating on them.
SIMON WILLISON

Introduction to Image Processing in Python With OpenCV

MUHAMMAD JUNAID KHALID

Projects & Code PayloadsAllTheThings: List of Useful Pentesting/CTF Payloads

GITHUB.COM/SWISSKYREPO

Carnets: Standalone Jupyter Notebooks Implementation for iOS

HOLZSCHU.GITHUB.IO

Pycel: Compile Excel Spreadsheets to Python Code & Visualize Them

GITHUB.COM/DGORISSEN

darknet.py: TOR Proxy Written in Python

GITHUB.COM/MULTIVERSECODER

dg: A Python With a Haskell Syntax

PYOS.GITHUB.IO

HiPlot: High-Dimensional Interactive Plots Made Easy

FACEBOOK.COM

Django Security: PyCharm Python Security Plugin

PYCHARM-SECURITY.READTHEDOCS.IO

DeepSpeed: Deep Learning Optimization Library

GITHUB.COM/MICROSOFT

Events JupyterCon 2020

August 10–14 in Berlin, Germany.
NUMFOCUS.ORG

Python Vienna Meetup

February 29, 2020
MEETUP.COM

Python Mauritius User Group Meetup

February 29, 2020
MEETUP.COM

PyDelhi User Group Meetup

February 29, 2020
MEETUP.COM

Melbourne Python Users Group, Australia

March 2, 2020
J.MP

Happy Pythoning!
This was PyCoder’s Weekly Issue #409.
View in Browser »

[ Subscribe to 🐍 PyCoder’s Weekly 💌 – Get the best Python news, articles, and tutorials delivered to your inbox once a week >> Click here to learn more ]

Categories: FLOSS Project Planets

Data School: How to merge DataFrames in pandas (video)

Tue, 2020-02-25 11:56

In my new pandas video, you're going to learn how to use the "merge" function so that you can combine multiple datasets into a single DataFrame.

Merging (also known as "joining") can be tricky to do correctly, which is why I'll walk you through the process in great detail. By the end of the video, you'll be fully prepared to merge your own DataFrames!

"This, by far, is the best explanation of these concepts." - M. Schuer

Click on a timestamp below to jump to a particular section:

1:21 Selecting a function (merge/join/concat/append)
3:36 Details of the merge process
12:07 Handling common merge issues
17:01 Comparing the four types of joins (inner/outer/left/right)

If you want to follow along with the code, you can download the Jupyter notebook and the datasets from GitHub.

Related Resources

If you have any questions, please let me know in the comments below!

Categories: FLOSS Project Planets

Real Python: How to Work With a PDF in Python

Tue, 2020-02-25 09:00

The Portable Document Format or PDF is a file format that can be used to present and exchange documents reliably across operating systems. While the PDF was originally invented by Adobe, it is now an open standard that is maintained by the International Organization for Standardization (ISO). You can work with a preexisting PDF in Python by using the PyPDF2 package.

PyPDF2 is a pure-Python package that you can use for many different types of PDF operations.

By the end of this course, you’ll know how to:

  • Extract document information from a PDF in Python
  • Rotate pages
  • Merge PDFs
  • Split PDFs
  • Add watermarks
  • Encrypt a PDF

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

Categories: FLOSS Project Planets

Podcast.__init__: Reducing The Friction Of Embedded Software Development With PlatformIO

Mon, 2020-02-24 22:25
Embedded software development is a challenging endeavor due to a fragmented ecosystem of tools. Ivan Kravets experienced the pain of programming for different hardware platforms when embroiled in a home automation project. As a result he built the PlatformIO ecosystem to reduce the friction encountered by engineers working with multiple microcontroller architectures. In this episode he describes the complexities associated with targeting multiple platforms, the tools that PlatformIO offers to simplify the workflow, and how it fits into the development process. If you are feeling the pain of working with different editing environments and build toolchains for various microcontroller vendors then give this interview a listen and then try it out for yourself.Summary

Embedded software development is a challenging endeavor due to a fragmented ecosystem of tools. Ivan Kravets experienced the pain of programming for different hardware platforms when embroiled in a home automation project. As a result he built the PlatformIO ecosystem to reduce the friction encountered by engineers working with multiple microcontroller architectures. In this episode he describes the complexities associated with targeting multiple platforms, the tools that PlatformIO offers to simplify the workflow, and how it fits into the development process. If you are feeling the pain of working with different editing environments and build toolchains for various microcontroller vendors then give this interview a listen and then try it out for yourself.

Announcements
  • Hello and welcome to Podcast.__init__, the podcast about Python and the people who make it great.
  • When you’re ready to launch your next app or want to try a project you hear about on the show, you’ll need somewhere to deploy it, so take a look at our friends over at Linode. With 200 Gbit/s private networking, node balancers, a 40 Gbit/s public network, and a brand new managed Kubernetes platform, all controlled by a convenient API you’ve got everything you need to scale up. And for your tasks that need fast computation, such as training machine learning models, they’ve got dedicated CPU and GPU instances. Go to pythonpodcast.com/linode to get a $20 credit and launch a new server in under a minute. And don’t forget to thank them for their continued support of this show!
  • You listen to this show to learn and stay up to date with the ways that Python is being used, including the latest in machine learning and data analysis. For even more opportunities to meet, listen, and learn from your peers you don’t want to miss out on this year’s conference season. We have partnered with organizations such as O’Reilly Media, Corinium Global Intelligence, ODSC, and Data Council. Upcoming events include the Strata Data in San Jose, and PyCon US in Pittsburgh. Go to pythonpodcast.com/conferences to learn more about these and other events, and take advantage of our partner discounts to save money when you register today.
  • Your host as usual is Tobias Macey and today I’m interviewing Ivan Kravets about PlatformIO, an open source ecosystem for IoT development including a cross-platform IDE, unified debugger, remote unit testing, and firmware updates.
Interview
  • Introductions
  • How did you get introduced to Python?
  • Can you start by describing what PlatformIO is?
    • What was your motivation for creating it?
    • What are the aspects of embedded development that keep you interested and engaged in this space?
  • What are some of the types of projects that someone might use PlatformIO to build?
  • What are some of the common challenges that a developer might encounter when working on embedded systems?
    • What are the additional complexities that get introduced as more hardware targets get added to a project?
  • What is the workflow for someone using PlatformIO for embedded systems development?
  • What are the different elements of PlatformIO and how do they simplify the work of building embedded systems projects?
  • How is PlatformIO implemented and how has the system design evolved since you first began working on it?
    • What was your reason for selecting Python as the implementation language?
    • If you were to start over today what would you do differently?
  • How has the embedded hardware and software landscape changed since you first started work on PlatformIO?
    • How has that impacted your product direction?
  • How do developers handle testing and validation of their applications?
  • How does PlatformIO help with updating deployed devices with new firmware?
  • What have been some of the most interesting/unexpected/innovative projects that you have seen built with PlatformIO?
  • What have been some of the most interesting/unexpected/challenging aspects of building and maintaining PlatformIO?
  • How are you approaching sustainability of the project and business?
  • What do you have planned for the future of PlatformIO?
Keep In Touch Picks Closing Announcements
  • Thank you for listening! Don’t forget to check out our other show, the Data Engineering Podcast for the latest on modern data management.
  • Visit the site to subscribe to the show, sign up for the mailing list, and read the show notes.
  • If you’ve learned something or tried out a project from the show then tell us about it! Email hosts@podcastinit.com) with your story.
  • To help other people find the show please leave a review on iTunes and tell your friends and co-workers
  • Join the community in the new Zulip chat workspace at pythonpodcast.com/chat
Links

The intro and outro music is from Requiem for a Fish The Freak Fandango Orchestra / CC BY-SA

Categories: FLOSS Project Planets

Catalin George Festila: Python 3.7.6 : The new concepts of execution in python 3 - part 001.

Mon, 2020-02-24 21:55
The main goal of these tutorials series is learning to deal with python source code using the new concepts of execution in python 3. When two or more events are concurrent it means that they are happening at the same time. Concurrent programming is not equivalent to parallel execution. In computing, concurrency is the execution of pieces of work or tasks by a computer at the same time.
Categories: FLOSS Project Planets

Talk Python to Me: #253 Moon base geekout

Mon, 2020-02-24 19:00
This episode is a unique one. On this episode, I've invited Richard Campbell and developer and podcaster who also dives deep into science and tech topics. We are going to dig into his geekout series and spend some time talking realistically about moonbases and space travel.
Categories: FLOSS Project Planets

Pages