A few basic tools I feel are missing in the standard Python distribution.
Project description
My Python Toolkit
This is just a miscellaneous collection of some tools I use regularly that I decided to compile into one package for easy use by mainly me. All examples will assume the package has been imported as kit
.
Install from PyPi: pip install mypytoolkit
.
import mypytoolkit as kit
Dates and Times
Time Now
kit.time_now()
returns a string of the current time in the format "%H-%M". Midnight is "00-00" and 8:35 a.m. is "08-35". 10 p.m. is "22-00". That's without optional parameters.
The optional parameter int_times: bool
will allow the function to return a tuple instead of a string. If you call kit.time_now(int_times = True)
, and if the time is 8:35 a.m., you will receive a tuple (8, 35)
where each element is an integer. This is useful for performing relative time actions within a program that are hour/minute independent.
kit.today_date()
returns a string of the current date in the format "%Y-%M-%D", where Feb 22, 2022, is "2022-02-22".
kit.time_decimal()
returns a float of the time. For example, if it is 8:45 a.m., the function will return 8.75.
Python Tools
kit.tprint()
displays the contents of an object along with its type. I got fed up of constantly writing print(obj, type(obj))
when debugging so I found myself constantly defining a tprint()
function:
def tprint(obj):
print(obj, type(obj))
return [obj, type(obj)]
Super simple but it makes a night and day difference when debugging in lightspeed.
Files
Tools for working with files.
Same Document Contents
kit.are_docs_same()
will tell you if two documents (of any type) have the exact same contents. It takes two parameters.
kit.are_docs_same(original_dir: str, new_dir: str)
It returns a boolean, True
or False
, depending on whether the contents of the two files are identical. There is no grey area.
Appending Content to Files
kit.append_by_query()
will append content to a file in a line below the first occurrence of a query. For example, if test.txt
has the contents:
this is line 1!
line 2 is here.
hello people!
line number 4.
And we run:
import mypytoolkit as kit
kit.append_by_query(
query = 'hello',
content = 'Just added this.',
file_path = 'test.txt',
insert_above = False # unnecessary, it is by default
)
test.txt
is modified in place and is now:
this is line 1!
line 2 is here.
hello people!
Just added this.
line number 4.
Math
Added a LinearEquation
class that takes attributes of slope and intercept on instantiation. It has a plot()
method which plots the linear graph. For example:
import mypytoolkit as kit
equation = kit.LinearEquation(slope = 4, intercept = 10)
equation.plot(interval = 1000)
This will output a matplotlib
plot of the linear equation from 0 to 1000.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mypytoolkit-1.3.0.tar.gz
.
File metadata
- Download URL: mypytoolkit-1.3.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1c0abd6470b33d0bbb90ec6fa9f75100a19dbd3bd68570240fec9796cee0ce0 |
|
MD5 | d66855dc16bef37ba52b95e53d17aaef |
|
BLAKE2b-256 | 5f3f4184897a63e1421cc0977af50774ba2cf577f080ffaf4d6932b417206335 |
File details
Details for the file mypytoolkit-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: mypytoolkit-1.3.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbc060d51ce70f4c3de2a6d97ba8fe7585776216c4c3d7065e88c557c70499ab |
|
MD5 | 052271150700a5e28ce2f8d47cd68876 |
|
BLAKE2b-256 | ece8f480ebe590f6a608b78ce99b62977e9c4aeedee14ec15582578ae0b3b4f5 |