Package: pylib-general
PyLib - GeneralThis is a package that will be updated whenever I get an idea that I like and write it.So far, I have:PropertiesNumTextExceptionsPropertiesThis can be used like:from pylib_general import propertiesimport pylib_general.properties as propertiesThis loads the Property class, which can be used like:varname = properties.Property()The property class's functions are:varname.add(name, val)namebeing the name of the new value (cannot contain spaces), andvalbeing the value.varname.remove(name)namebeing the name of the value to removevarname.get(name)returns the value ofnameThe difference between Property and other sets is that you can get a property in a much easier way:varname.attrObviously, you can also get a value throughvarname.get(name)but you could also dovarname.nameEx:varname = Property().add("somenamenotcontainingnumbersorspaces", "12233090")
print(varname.somenamenotcontainingnumbersorspaces)prints12233090A hidden way to get values isvarname.__dict__["name"](Not preferable)calling that,varname.attr,del varname.attr, orvarname.attr = valwill call the get, remove, and add functions respectively.NumThis can be used like:from pylib_general import numimport pylib_general.num as numThis loads the number functions, which are:num.factorial(n)Wherenis the number you want to factorial, returns n!num.sig(n)Wherenis the number you want to sigma, returns n + (n-1) + (n-2) ...num.pow(n, p)Wherenis the number you want to raise to the power ofp. Returns n^p (python syntax:n**p)num.incr(n)Wherenis the number to increment by 1. Returns n + 1num.decr(n)Wherenis the number to decrement by 1. Returns n - 1num.mod(n, d)Wherenis the number to modulo withd. Returns n % dnum.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.piEquals 22/7TextThis can be used like:from pylib_general import textimport pylib_general.text as texttext.checkstr(ost)Checks ifostis a string or not. returns True or False.text.rev(ost)Returns the reverse of the stringosttext.ascii_convert(ost)Takesostand 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)Takesostand shifts the characters by a key, giving theCaesar Cipheredversion of it as a string.
Ex:text.caesarcipher("ccC")returns "ddD"text.weirdcase(ost)Takesostand makes every other letter uppercase.
Ex:text.weirdcase("ccced")returns "CcCeD"
Note: if instead of "CcCeD" you want "cCcEd," you can usetext.weircase("ccced").swapcase()text.encode(ost, key=1)Ah, here is the masterpiece of the text module: encode! It takesostand reverses the the ascii version of the weirdcase of the caesarcipher ofost.The code for the return value isrev(ascii_convert(weirdcase(caesarcipher(ost, key))))Ex:text.encode("ccC")returns "86-001-86"text.checkpalindrome(ost)Takesostand checks if it is apalindrome.ExceptionsThis can be used like:from pylib_general import exceptionsimport pylib_general.exceptions as exceptionsexceptions.ErrorLiterally just an exception, except under a different name.exceptions.NumTooLowError(value, message="Value was too low.")whenraised, showsexceptions.NumTooLowError: 112: Value was too low.(assuming the value parameter was 112)exceptions.NumTooHighError(value, message="Value was too high.")when raised, showsexceptions.NumTooHighError: 112: Value was too high(assuming the value parameter is 112)exceptions.NumNotInRangeError(nrange, value, message="Value not in range ")when raised correctly, showsexceptions.NumNotInRangeError: 112: Value not in range (2, 99)(assuming the nrange passed was [2, 99] and the value passed was 112)