Arie Bregman

Linux And Stuff

Category: Python (page 1 of 2)

Python: Working with Jinja2 templates

In this post we’ll see how to work with Jinja2 in your Python projects, to easily create and modify templates.

Jinja2 is widely used and you probably already noticed it if you used projects such as Flask and Ansible or even if you simply searched for a robust templating engine.I can describe its greatness for a couple of minutes if not hours, but the

I can describe its greatness for a couple of minutes if not hours, but the official doc does it much better, so I recommend to go over them to get an idea on what you can achieve by using it. This post is mainly for those who are looking for a quickstart guide.

Continue reading

Python: check if two strings are permutations of each other

Another question I cover in a presentation I’m preparing for “Open University meets Open Source” meetups.

What is a Permutation?

Permutation is the action of rearranging objects, characters or symbols into different, unique sequences.

Each sequence is called ‘permutation’.

It’s common to see people mix permutation with combination, but those are two different things. Remember, combination doesn’t care about the order, while permutation does.

Continue reading

Python: check if one string is a rotation of another string

Another question I cover in a presentation I’m preparing for “Open University meets Open Source” meetups.

The question

You have two strings, str1 and str2 and you need to return True if the first string is a rotation of the second string. Otherwise, return False.

Examples

“hello”,    “llohe” -> True. If we’ll rotate the second string twice, you’ll get ‘hello’.

Continue reading

Python: Working with RPMs

In this post I’ll cover:

  • Using the dnf module for querying for RPMs
  • Exctract RPM details with re module
  • Comparing RPM versions

The complete code is included at the end.

Query for RPMs

In this part I’ll show you how to use the DNF module in order to search for RPMs and extract information on them such as arch, version and name.

Continue reading

Python: Objects comparison

One of the most common questions I get asked by python beginners, is “how do you compare between objects of a class?”

To answer this question, let’s have a look on the following class:

Continue reading

Older posts

© 2017 Arie Bregman

Theme by Anders NorenUp ↑