yuval.guide — Guides and hands-on courses on DevOps, cloud, Linux, Python, Kubernetes, networking and AI.
If you were following the Iterators post, you could think that creating iterable object or generators (that could provide an iterator) in python is not so easy. You should be able to create a class, then implement those special methods, make sure everything works.. But there are easier ways. Creating a Generator with …
Read MoreIn this basic post we'll explain the basics of iterators. A Python Iterator If a python object contains some collection of objects, we need a way to get these object, one at a time. Note that: A specific order is optional, but we must make sure that: ..we get each object ONCE, and.. ..eventually we get ALL objects. …
Read MoreWe have covered default values for parameters during our discussion of function parameters. We now want to explain some more details about that. Python IS dynamic If you are coming from static programming languages (C, C++, Java, C#, Rust, Golang etc..) then you should remind yourself that in python EVERYTHING happens …
Read MoreIn this example, we create a decorator that will multiply a value returned by a 2 parameters func by a value. What we want to achieve Suppose you have a decorator and a function like the following: 1@mult(5) 2def add_nums(a,b): 3 return a+b The idea is that instead of having add_nums(3,4) return 7, it will return 35. …
Read MoreAbout bytes The python bytes type represents abinary sequence of bytes. I use the term "binary" because it is sometimes displayed as a sequence of characters, but it it not text, not it it a string! bytes is immutable, whereas bytearray is a mutable version of it. representation A bytes object looks like a string, with …
Read MoreThe tasks project Flask is a micro web framework. You can use it to create web sites, but also to create web services, which are programs that communicate over the http protocol. We'll use it here to create a simple web service and api. In our api, we'll send and receive JSON strings to represent tasks Installation …
Read MoreFunction decorators are used in many python packages and libraries. Often, you see the @ sign in code before you learn what it is, so you get back to read about decorators. We'll use a simple example to demonstrate the use of decorators. What do we try to achieve Suppose you have a simple, 2 params function like the …
Read MoreOpen Function Basics The open function documentation contains a lot of parameters The only positional parameter (file) specifies the path of the file to be read.
Read MoreInteractive courses Python Foundations — Python from nothing, in the browser, as slides beside a Python editor: names and numbers, strings, loops, lists, dictionaries and sets, functions, files and JSON, exceptions, and classes as far as inheritance. Every example runs in the page and every exercise is checked; nothing …
Read MoreAbout bash functions Also called Shell Functions Once a function is defined, it is used like a "regular" command Shell functions are executed in the current shell context; no new process is created to interpret them. Function Syntax Functions are declared using this syntax: 1fname () compound-command [ redirections ] 2 …
Read More