Skip to main content

A Python package full of small & useful functions to make your life easier.

Project description

Pyopt-tools

PyOpt-tools contains a set of mirco function most of these functions are easy but most of us don't want to waste time searching for "how to reverse a string in python" or "how to sort a list by type in python" but as you're here I am assuming you fall into "most of us" category.

You may find some function useful for you, but you may also find some of them useless. because there just way too small and you can write them anytime but It's not about the functions' complexity. it's about knowing how to do it. most of us don't want to spend time finding functions like this just to prototype a project or just to test a function.

Full Documentation

What kind of functions?

Functions are separated into different files. there are currently string_tools, math_tools, list_tools and also pyvec pyvec contains vector 2 and 3 class that has some useful vector maths for game development. or you can use it to do normal stuff (not that game development isn't normal just saying)

Every function has proper documentation and comments with examples. But I also included all the functions in example file. Which will be updated as I add more functions.

Some Functions it includes

from pyopt_tools import listools
from pyopt_tools import string_tools
from pyopt_tools import math_tools
from pyopt_tools.pyvec import Vec2, Vec3
from pyopt_tools import file_tools

## string tools
print("Split str", string_tools.split_str("Hello World", 2))
print("Randomize String", string_tools.randomize_string("Hello world"))
print("encodeMorse", string_tools.encodeMorse("Hello world"))
print("decodeMorse", string_tools.decodeMorse(".... . .-.. .-.. ---   .-- --- .-. .-.. -.."))
print("to_binary", string_tools.to_binary("Hello"))
print("bin_to_text", string_tools.bin_to_text("1001000 1100101 1101100 1101100 1101111"))  # only works with spaces
print("Reverse String", string_tools.reverse_string("Hello world"))


## math tools
print("reverse_int", math_tools.reverse_int(123))
print("persistence", math_tools.persistence(1234))
print("is_square", math_tools.is_square(6))
print("is_pentagonal", math_tools.is_pentagonal(6))
print("is_hexagonal", math_tools.is_hexagonal(5))
print("lerp", math_tools.lerp(0, 10, 0.5))
print("clamp", math_tools.clamp(0, 10, -1))

# pyvec # Vec2 and Vec3 contains all same functions
print("Vec2", Vec2(1, 2))
print("Vec3", Vec3(1, 2, 3))
print("Vec2.dot", Vec2(1, 2).dot(Vec2(3, 4)))
print("Vec3.cross", Vec3.cross(Vec3(1, 2, 3), Vec3(3, 4, 5)))  # static method

## list tools
test_list = [2, "hello", 1, 3, 3, 3, 3, 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, "hello"]
print("listools.remove_duplicates",
      listools.remove_duplicates(test_list))
print("listools.remove_duplicates_sort",
      listools.remove_duplicates_sort(test_list))
print("listools.sort_list", listools.sort_list([2, 3, 2, 1, "string1", "string2", "string3",  3.3, 2.2], (str, int, float), sort_elements=True)) # sort list by types and in which order also option to sort each element in the list
# find string in multiple files in the given folder
result = file_tools.find_in_files("F:/Important Folder/", "test string", ["py", "cup", "txt"])
for res in result:
    filename, line, string = res
    print("file_tools.find_in_files", repr(filename), line, repr(string))

Check out documentation for more information

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyopt-tools-0.7.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyopt_tools-0.7-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file pyopt-tools-0.7.tar.gz.

File metadata

  • Download URL: pyopt-tools-0.7.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for pyopt-tools-0.7.tar.gz
Algorithm Hash digest
SHA256 a138468421c5db0c9fab77f56e28a9165d149588c46dbe30141729c71b394ce7
MD5 9294cf9939e065aeac7e02f28200cf9b
BLAKE2b-256 d51c0216944cf6efc5750521ccba01e9b0e065fd903d3b22c2762d638427bc3e

See more details on using hashes here.

File details

Details for the file pyopt_tools-0.7-py3-none-any.whl.

File metadata

  • Download URL: pyopt_tools-0.7-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.2

File hashes

Hashes for pyopt_tools-0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6277d8df69e0a8803998ccf387e842b863f92cdd6147e24f43552276a64a5383
MD5 789eb1ab1d655ebce382f983bcae20f3
BLAKE2b-256 1f1a1748dbea63837419e97af1b80df0e46247ff14c1fd9d983dc379691e9c8a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page