Archives de catégorie : Non classé

Iterations with python

Loop for in statement: iterate over any sequences The sequence can be a list,a string,a tuple and so for… in python this statement is very very very common. In fact for most of things we need to iterate we will … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

execute a command with python

Execute shell process with subprocess module (Python 3.5) goal and general advices goal: The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several older modules … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

regex in python

Raw regex It is very different from the java approach that doesn’t have that capacity. It allows to escape in a clever way: we escape only when needed. Example here with classic regex: two main ways to use regex – … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

python imports

Definitions Module: a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module name (as a string) is available as the value of the global variable __name__. … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

File and path in python with pathlib api

common functions and variables Functions to create or retrieve path objects Create a path pointing to the current working directory (as returned by os.getcwd()) : cwd: Path = Path.cwd() Create a path by concatenating a Path with a String object: … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

write and read file in python

Read text files By default python reading file API preserves the break-line character (\n on Linux for example). in the example below we mean by « cleaned lines »,lines that we removed the break line characters Read lines in memory: def read_lines_in_memory(filename: … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Ergonomic tricks

Windows And Linux Native Copy: Ctrl+Ins Cut: Shift+Del Paste: Shift+Ins Windows apps PowerToys Rebind some keys or keys combination.– to reduce the thumb painful combination with Alt + keys  in the left side such as : Alt + Tab, Alt … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

Python – Asyncio

Purpose and overview asyncio is a library to write concurrent code using the async/await syntax. At its core, it relies on an event loop model processing coroutines, so it uses only one thread. It is is used as a foundation … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

python unit testing

unittest API General – add the tests files/fixtures in a test folder at the root of the project. The folder may have any name in last Python 3 versions. – create an empty file __init__.py at the root of the … Continuer la lecture

Publié dans Non classé | Laisser un commentaire

python venv

Introduction When using that ? In almost every applications. The python and packages installed on the host may suit to some applications needs but not to all. To settle that : the venv module. That is the standard python module … Continuer la lecture

Publié dans Non classé | Laisser un commentaire