Skip to main content

general python features that may come in handy at some point.

Project description

PyLib - General

This is a package that will be updated whenever I get an idea that I like and write it.

So far, I have:

Properties

This can be used like:

from pylib_general import properties import pylib_general.properties as properties

This loads the Property class, which can be used like:

varname = properties.Property()

The property class's functions are:

  • varname.add(name, val)

name being the name of the new value (cannot contain spaces), and val being the value.

  • varname.remove(name) name being the name of the value to remove

  • varname.get(name) returns the value of name

The difference between Property and other sets is that you can get a property in a much easier way:

varname.attr

Obviously, you can also get a value through varname.get(name) but you could also do varname.name

Ex:

varname = Property().add("somenamenotcontainingnumbersorspaces", "12233090")
print(varname.somenamenotcontainingnumbersorspaces)

prints 12233090

A hidden way to get values is varname.__dict__["name"] (Not preferable)

calling that, varname.attr, del varname.attr, or varname.attr = val will call the get, remove, and add functions respectively.

Num

This can be used like:

from pylib_general import num import pylib_general.num as num

This loads the number functions, which are:

  • num.factorial(n)

Where n is the number you want to factorial, returns n!

  • num.sig(n)

Where n is the number you want to sigma, returns n + (n-1) + (n-2) ...

  • num.pow(n, p)

Where n is the number you want to raise to the power of p. Returns n^p (python syntax: n**p)

  • num.incr(n)

Where n is the number to increment by 1. Returns n + 1

  • num.decr(n)

Where n is the number to decrement by 1. Returns n - 1

  • num.mod(n, d)

Where n is the number to modulo with d. Returns n % d

  • num.get_fibo(terms)

Where terms is the number of terms of the Fibonacci sequence you want to get. Returns array. Special usage: get_fib(3)[2] will return 1, same as _recur_fib(2) (preferably not used)

  • num.pi

Equals 22/7

Text

This can be used like:

from pylib_general import text import pylib_general.text as text

  • text.checkstr(ost)

Checks if ost is a string or not. returns True or False.

  • text.rev(ost)

Returns the reverse of the string ost

  • text.ascii_convert(ost)

Takes ost and converts it's characters into their ascii codes separated with hyphens (dashes). Returns string. Ex: text.ascii_convert("ccC") returns "99-99-67"

  • text.caesarcipher(ost, key=1)

Takes ost and shifts the characters by a key, giving the Caesar Ciphered version of it as a string. Ex: text.caesarcipher("ccC") returns "ddD"

  • text.weirdcase(ost)

Takes ost and makes every other letter uppercase. Ex: text.weirdcase("ccced") returns "CcCeD" Note: if instead of "CcCeD" you want "cCcEd," you can use text.weircase("ccced").swapcase()

  • text.encode(ost, key=1)

Ah, here is the masterpiece of the text module: encode! It takes ost and reverses the the ascii version of the weirdcase of the caesarcipher of ost. The code for the return value is rev(ascii_convert(weirdcase(caesarcipher(ost, key)))) Ex: text.encode("ccC") returns "86-001-86"

  • text.checkpalindrome(ost)

Takes ost and checks if it is a palindrome.

Exceptions

This can be used like:

from pylib_general import exceptions import pylib_general.exceptions as exceptions

  • exceptions.Error

Literally just an exception, except under a different name.

  • exceptions.NumTooLowError(value, message="Value was too low.")

when raised, shows exceptions.NumTooLowError: 112: Value was too low. (assuming the value parameter was 112)

  • exceptions.NumTooHighError(value, message="Value was too high.")

when raised, shows exceptions.NumTooHighError: 112: Value was too high (assuming the value parameter is 112)

  • exceptions.NumNotInRangeError(nrange, value, message="Value not in range ")

when raised correctly, shows exceptions.NumNotInRangeError: 112: Value not in range (2, 99) (assuming the nrange passed was [2, 99] and the value passed was 112)

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

pylib-general-0.2.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

pylib_general-0.2.3-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file pylib-general-0.2.3.tar.gz.

File metadata

  • Download URL: pylib-general-0.2.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for pylib-general-0.2.3.tar.gz
Algorithm Hash digest
SHA256 cab26bdccf83bee47fe7a5487147ddd5d8c43ea4effaacf165e7d9bf53923f99
MD5 51db30c95a7940a2d86e6373c011e205
BLAKE2b-256 ee84de3d0fa515558e0535584e0bbecf6e7019202cb8ab1f1ea546858fe18116

See more details on using hashes here.

File details

Details for the file pylib_general-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: pylib_general-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for pylib_general-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bb09e9e36972e715e7ef0201135871d57b8f3df132ed9b6e633f7d93efe9cf08
MD5 87b50dded8590421b57aff9400b9132d
BLAKE2b-256 597011dd244c0e323a87f56facc8d50d0845509a0c2aa296cbc10655242ae073

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