TOOLS#

Module tools contains some useful functions that I usually use for Python coding.

FUNCTION read_file#

mdsanima_dev.utils.tools.read_file(file_path: str) str#

Function reads the file and splits it into separate lines.

Parameters:

file_path (str) – File path to read and split.

Returns:

List of lines in the string by line and the total number of lines.

Return type:

str

Usage:

Assigning function calling to a variable:

lines, lines_len = read_file(file_path)

FUNCTION append_file#

mdsanima_dev.utils.tools.append_file(file_path: str, data: str) str#

Function save data into file.

Parameters:
  • file_path (str) – File path to save data with append mode.

  • data (str) – Data to write into file one line.

Usage:

Function calling:

append_file(file_path, data)

FUNCTION get_response_json#

mdsanima_dev.utils.tools.get_response_json(url: str)#

Function get response json dictionary from url.

Parameters:

url (str) – URL address to get response json.

Returns:

Dictionary data.

Return type:

json

Usage:

Function calling:

get_response_json(url)

FUNCTION machine#

mdsanima_dev.utils.tools.machine(text: str, speed: int = 0.1) str#

Function printing text as a typing on screen at intervals time after each letter.

Parameters:
  • text (str) – Text to be entered as an animation.

  • speed (int, optional) – Time after each print letter, defaults to 0.1.

Returns:

Printing text in the console as an animation.

Return type:

str

Usage:

Function calling:

machine("I love Python")
../../_images/mdsanima_dev_python_machine.gif

CLASS progress#

class mdsanima_dev.utils.tools.progress(txt_first: str = 'get data', txt_end: str = 'done', txt_first_color: int = 112, txt_end_color: int = 192, bar_sten_color: int = 203, bar_color: int = 113, percent_color: int = 243)#

Progress bar animation.

Usage:

Animation progress bar:

progress().progress_bar(100, 0.01)

Animation progress bar with indiwidual percent color:

progress(percent_color=232).progress_bar(100, 0.01)

METHOD __init__()#

progress.__init__(txt_first: str = 'get data', txt_end: str = 'done', txt_first_color: int = 112, txt_end_color: int = 192, bar_sten_color: int = 203, bar_color: int = 113, percent_color: int = 243) str#

Initial function. These values can be set individually to the different progress bar.

Parameters:
  • txt_first (str, optional) – First text, defaults to get data.

  • txt_end (str, optional) – End text, defaults to done.

  • txt_first_color (int, optional) – Color first text, defaults to 112.

  • txt_end_color (int, optional) – Color end text, defaults to 192.

  • bar_sten_color (int, optional) – Color parenthesis, defaults to 203.

  • bar_color (int, optional) – Color bar progress, defaults to 113.

  • percent_color (int, optional) – Color percent text, defaults to 243.

Returns:

One line progress bar animation.

Return type:

str

METHOD progress_conf()#

progress.progress_conf(percent: int, width: int) str#

This function is a configuration of the progress bar. You can use this function if you want to make your own for loop.

Parameters:
  • percent (int) – Percent value of the progress bar.

  • width (int) – Width of the progress bar.

Returns:

One line progress bar.

Return type:

str

METHOD progress_bar()#

progress.progress_bar(width: int, speed: int) str#

This function pringint animation of progress bar in one line.

Parameters:
  • width (int) – Width of the progress bar.

  • speed (int) – Speed of the progress bar left to right.

Returns:

One line progress bar with color and animation.

Return type:

str

../../_images/mdsanima_dev_python_progress.gif