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.2.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.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pylib-general-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 5e93ca14181fb58207c833f5b786d917e32ed2dab227553c097e3e6a54889800
MD5 cc768d134034081c9b24891f70c06d5b
BLAKE2b-256 ecafdd1c936020a91d22451f2ae6fc4c7e1982a75cb73a74393dfcfc2da8512a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pylib_general-0.2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 75264c4cdc217ab5e3bf655c53920367735a099d734777ae29eae64c45134959
MD5 dbcbecf0530a06fce37f37733a623902
BLAKE2b-256 9c04b42274d1a242263c780e6bc7f51ffcfc0dd5f3a568eb2d941a0c094f9cc8

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