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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pylib-general-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 1cb54372b33a541b1e1e6ff34ef3efbf8e953ebbcb87adcdfeb23121b4f399fd
MD5 e8b48b48a27186effce22cb884c46f0b
BLAKE2b-256 4517c6db5e00a6a49ee86a4e1f7534cf9eaee43a4ef9ca8157d992f25570613d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pylib_general-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 70b11c5f31dc6e9c607aa539273de89183fde2e300c600d72d1352ebeec26b15
MD5 d8a7abfba1a882b5b33b01ab92e20298
BLAKE2b-256 2ec2de125dfdf140bed270c03b3dd5eb308029143ba2d1314df8a407022084e6

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