GitHub - Python-Geek-Labs/PythonTools: A collection of tools for Python that I created for my personal use. · GitHub
CodeOpen more actions menu
Folders and files
NameNameLast commit message
Last commit date
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
View all files |
Repository files navigation
A collection of tools for Python that I created for my personal use.
│ .gitignore
│ LICENSE
│ README.adoc
│ README.pdf
│
├───.github # GitHub CI
│ └───workflows
│ dependencies.txt # Dependencies for unit tests
│ doc.yml # Convert README to PDF
│ test.yml # Run unit tests and coverage
│
├───python_tools # Python package
│ debug_tools.py
│ math_tools.py
│ __init__.py
│
└───test # Package containing unit tests
test_debug_tools.py
test_math_tools.py
__init__.py
import python_tools as pt
Tools that can be used for debugging.
3.1. Debug Wrapper @debug
A debug wrapper that prints some useful information about a function call.
This wrapper can be used by placing the corresponding decorator above the declaration of the function.
import python_tools as pt
@pt.debug
def a_function(x, y, z):
pass
--debug--debug--debug--debug--debug--debug--debug--debug--debug--debug--
-- Function: a_function(x, y, z)
-- Arguments: (1, 2, 3)
-- Returned: None
-- Time elapsed [s]: 0.0
--debug--debug--debug--debug--debug--debug--debug--debug--debug--debug--
3.2. Timer Wrapper @timer
This wrapper can be used by placing the corresponding decorator above the declaration of the function.
import python_tools as pt
@pt.timer
def a_function(x, y, z):
pass
--timer--timer--timer--timer--timer--timer--timer--timer--timer--timer--
-- Function: a_function(x, y, z)
-- Time elapsed [s]: 0.0
--timer--timer--timer--timer--timer--timer--timer--timer--timer--timer--
3.3. Run Function and get STDOUT run_fct_get_stdout(fct: callable, *args) → str:
Runs a function and collects stdout during the execution of said function and returns the collected stdout as a string.
>>> import python_tools as pt
>>> pt.run_fct_get_stdout(print, 'Hello world!')
'Hello world!\n'
Tools related to mathematics
4.1. Sum from 1 to n sum_1_n(n: int) → int
This function calculates the sum of all numbers from 1 to n.
>>> import python_tools as pt
>>> pt.sum_1_n(10)
55
4.2. Lower Triangular Number ltm(n: int) → int
This function returns n if it is a triangular number, or the next lower triangular number.
>>> import python_tools as pt
>>> pt.ltm(16)
15
4.3. Is Triangular? is_triangular(n: int) → bool
This function checks if a number is triangular.
>>> import python_tools as pt
>>> pt.is_triangular(15)
True
>>> pt.is_triangular(16)
False
>>> pt.is_triangular(21)
True
Tools related to the internet and webpages.
5.1. Is Page up is_page_up(url: str) → bool
Tests if a webpage is up (returns 200).
>>> import python_tools as pt
# Test an existing url
>>> pt.is_page_up('https://www.twitter.com/')
True
# Test an url that doesn't exist
>>> pt.is_page_up('https://www.a1s2d3e5f2c5e4d2f5r1e23c5e1.com/')
False
About
A collection of tools for Python that I created for my personal use.
Resources
License
Stars
Watchers
Forks
Footer
You can’t perform that action at this time.