A utility package influenced by java, coded in python
Project description
Influence - The Python Extender You Asked For
With influence you can extend python with things like two-dimensional
lists, fractions, string subtractors, etc. You can also upgrade python
with things it doesn’t have like arrays!
Overview
The influence python library was created with one sole purpose, helping
you do things that can’t be done in standard python with ease
Usage
Below is how to install and use the influence library in your own
programs!
Installation
$ pip install influence
or
$ python3 -m pip install -U influence
The influence package has two package dependencies, numpy and matplotlib
(used for grapher and agrapher classes)
Cout
Cout (common output) has only one class, printer, that helps print
tuples, lists, dicts, etc. nicely
Importing:
from influence import cout
#or
from influence.cout import Printer
Printer Class
Methods:
Printer.print_list(list) #prints a list nicely
Printer.print_tuple(tuple) #prints a tuple nicely
Printer.print_dictionary(dict) #prints a dict nicely
Printer.print_all(ender, *items)
#prints all of items, if ender is False, prints each item on new line
#else all items are printed on the same line
Cin
‘’’
Cin (common input), has one class, input, that handles input
specifically
Importing:
from influence import cin
#or
from influence.cin import Input
Input Class
Methods:
value = Input.input(t, prompt=None)
#stores input into value
#prompt will be printed, defaults to None
#raises ValueError if input does not match type t
#raises TypeError if t not able to be casted from input
List2D Class
Creates a 2D list of a square size
Importing:
from influence.list import multilist
#or
from influence.list.multilist import List2D
Initializing:
l = List2D(rows=1, cols=1)
#creates the list to have rows number of rows and cols number of cols
Methods:
l[r_index][c_index] = item
#sets value at r_index and c_index to item
#raises IndexError if index out of bounds
l[r_index].append(item)
#since this is a list, if you wish to append the list
#you can do it this way instead of settings
l[r_index][c_index]
#returns value at r_index and c_index
#raises IndexError if index out of bounds
l.print()
#prints the list
l.remove(r_index, c_index)
#removes the value at r_index and c_index
#returns true if removed, false if index out of bounds
item in l
#returns true if item in l, false otherwise
l.index(item)
#returns indices of item if found in list
#returns [-1] otherwise
l.__len__() / len(l)
#returns the length of l
l.__str__() / str(l)
#returns l as a str
l.__delitem__(key) / del l[key]
#deletes row key from l
#raises IndexError if key out of bounds
RaggedList Class
Creates a 2D list, but doesn’t need to be of n x n size, inherits from
List2D, and therefore has a dependency to
influence.extender.list.multilist
Importing:
from influence.list import ragged
#or
from influence.list.ragged import RaggedList
Initializing:
r = RaggedList(rows=1, cols=1)
#creates a ragged list starting with rows rows and cols cols
#defaults to one for both if no arguments are given
Methods:
r.print()
#prints the ragged list
r.in_bounds(r_index, c_index)
#returns true if r_index and c_index are in bounds of the list
#returns false otherwise
r.set(r_index, c_index, item)
#sets value at r_index and c_index to item if in bounds
#else extends the ragged list so r_index and c_index are in bounds
r.get(r_index, c_index)
#returns value at r_index and c_index if in bounds
#else returns None
item in r
#returns true if item is in r, else returns false
r.index(item)
#returns the indices of item if in r
#else returns [-1]
r.__len__() / len(r)
#returns the length of r
AsList Class
Used to turn strings into lists, duplicate class found in string
subpackage
Importing:
from influence.list import aslist
#or
from influence.list.aslist import AsList
Methods:
AsList.character_list(string)
#returns string as a list of characters
AsList.word_list(string)
#returns string as a list with each word
#a word is found when a space is reached in the string
#spaces are not included in the list
AsList.word_list_with_spaces(string)
#same as AsList.word_list(string) except spaces are part of the list
AsList Class
Used to turn strings into lists, duplicate class found in list
subpackage
Importing:
from influence.string import aslist
#or
from influence.string.aslist import AsList
Methods:
AsList.character_list(string)
#returns string as a list of characters
AsList.word_list(string)
#returns string as a list with each word
#a word is found when a space is reached in the string
#spaces are not included in the list
AsList.word_list_with_spaces(string)
#same as AsList.word_list(string) except spaces are part of the list
Subtract Class
Allows for subtracting of strings, but does not change the input string,
instead returns a new string
Importing:
from influence.string import subtract
#or
from influence.string.subtract import Subtract
Methods:
Subtract.subtract(initial, remove)
#removes the first instance of remove from initial
#returns a new string
#remove can be multiple letters, but must be a string
Subtract.subtract_all(initial, remove)
#removes all instances of remove from initial
#returns a new string
#remove can be multiple letters, but must be a string
Const Class
Gives the user access to constants in math
Importing:
from influence.math import const
#or
from influence.math.const import MathConstants
Fields:
MathConstants.pi #returns the value of pi
MathConstants.e #returns the value of e
MathConstants.tau #returns the value of tau
MathConstants.phi #returns the value of phi
Stats Class
Allows for statistics with int or float datasets
Importing:
from influence.math import stats
#or
from influence.math.stats import Stats
Methods:
Stats.min(dataset)
#returns the lowest value in dataset
Stats.max(dataset)
#returns the highest value in dataset
Stats.range(dataset)
#returns the range of the dataset (max - min)
Stats.mean(dataset)
#returns the mean of the dataset
Stats.variance(dataset)
#returns the variance of the dataset
Stats.standard_deviation(dataset)
#returns the standard deviation of the dataset
Stats.median(dataset)
#returns the median of the dataset
Stats.mode(dataset)
#returns the mode of the dataset as a list
Cos Class
Does permutations and combinations equations, inherits from Stats, and
therefore has a dependency to influence.extender.math.stats
Importing:
from influence.math import cos
#or
from influence.math.cos import Combinatorics
Methods:
Combinatorics.factorial(num)
#returns the factorial of num
Combinatorics.P(n, r)
#returns the permutations equation (n! / (n-r)!)
Combinatorics.C(n, r)
#returns the combinations equation (n! / [(n-r)! * r!])
Frac Class
Represents a fraction
Importing:
from influence.math import frac
#or
from influence.math.frac import Fraction
Initializing:
f = Fraction(num, denom)
#initializes a fraction to numerator num and denominator denom
Methods:
f.simplify()
#simplifies this fraction, if possible
f.__float__() / float(f)
#returns the float value of the fraction
f.__int__() / int(f)
#returns the int value of the fractions
f.__str__() / str(f)
#returns the fraction as a string
f.to_mixed_number(self)
#returns f as a mixed number
Compare:
f1 = Fraction(1, 2)
f2 = Fraction(3, 4)
#fraction allows for
f1 < f2
f1 <= f2
f1 == f2
f1 > f2
f1 >= f2
MixedNum Class
Represents a mixed number
Importing:
from influence.math import mixednum
#or
from influence.math.mixednum import MixedNumber
Initializing:
m = MixedNumber(coeff, num, denom)
#creates a mixed number with a coefficient coeff, numerator num
#and denominator denom
Methods:
m.simplify()
#simplifies this mixed number, if possible
m.__float__() / float(m)
#returns the float value of the mixed number
m.__int__() / int(m)
#returns the int value of the mixed number
m.__str__() / str(m)
#returns the mixed number as a str
m.to_fraction()
#returns the mixed number as a new improper fraction
Compare:
m1 = MixedNumber(1, 2, 3)
m2 = MixedNumber(4, 5, 6)
#fraction allows for
m1 < m2
m1 <= m2
m1 == m2
m1 > m2
m1 >= m2
Grapher Subpackage
Allows for graphing equations
Importing:
from influence.math.grapher import Equation
from influence.math.grapher import GraphingError
from influence.math.grapher import Grapher
Equation Class:
Represents an equation
Initializing:
e = Equation(eq)
#eq cannot be inferred
#ie 4x+3 needs to be 4*x+3
#ie 4x^2+2 needs to be 4*(x**2)+3
GraphingError Class:
GraphingError.HostileAttackError is thrown when a hostile attack is
detected with eval GraphingError.InstanceError is thrown when graphing,
the parameter is not an instance of Equation
Grapher Class:
Grapher.graph(eq)
#graphs eq, if and only if isinstance(eq, Equation) returns True
Agrapher Subpackage
Asynchronous graphing is currently a WIP but are still able to be used
Importing:
from influence.math.asyncgrapher import Equation
from influence.math.asyncgrapher import GraphingError
from influence.math.asyncgrapher import Grapher
Agrapher works in the same exact way except Grapher.graph(eq,
timetoclose=None), can have a given timeout
Array Class
Makes an array. An array is like a list, except it has a definite,
unchangeable size, but elements can be changed inside of it (unlike a
tuple)
Importing:
from influence.array import arrays
#or
from influence.array.arrays import Array
Initializing:
arr = Array(capacity)
#initializes the array to its definite length
Methods:
arr[index]
#gets the value at index
arr[start:stop:step]
#returns a list from an array from a slice of start, stop, and step
#raises IndexError if index out of bounds
arr[index] = item
#sets the value at index to item
#raises IndexError if index out of bounds
arr.__iter__() / iter(arr)
#returns an iterator for the array
iterator.__next__() / next(iterator)
#gets the next element from the iterator
arr.print()
#prints the array
item in arr
#returns true if item is in arr, false otherwise
arr.index(item)
#returns the index of item if in arr
#returns -1 if not found
arr.__len__() / len(arr)
#returns the length of arr
not arr
#returns True if arr has a capacity of 0
arr.__str__() / str(arr)
#returns arr as a str
arr1 + arr2
arr1 += arr2
#adds the arrays together
Array2D Class
Creates a 2D Array, inherits from Array, and therefore has a dependency
to influence.upgrader.array.arrays
Importing:
from influence.array import multiarray
#or
from influence.array.multiarray import Array2D
Initializing:
arr = Array2D(r, c)
#creates a 2D array to a fixed amount of rows (r) and columns (c)
Methods:
arr[r_index][c_index]
#returns the value at r_index and c_index
#raises IndexError if index out of bounds
arr[r_index][c_index] = item
#sets value at r_index and c_index to item
#raises IndexError if index out of bounds
arr.print()
#prints the 2D array
item in arr
#returns true if item is in arr, false otherwise
arr.index(item)
#returns the indices of item in arr, if found
#returns [-1] otherwise
arr.__len__() / len(arr)
#returns length of arr
StringBuffer Class
Makes strings mutable, like in java
Importing:
from influence.string import stringbuffer
#or
from influence.string.stringbuffer import StringBuffer
Initializing:
s = StringBuffer(str='')
#initializes a string buffer to str, empty if none entered
Methods:
s.__len__() / len(s)
#returns the length of s
obj in s
#returns true if obj is in s, false otherwise
s.__iter__() / iter(s)
#returns an iterator for s
s.__next__() / next(s)
#gets next letter in s
s.__str__() / str(s)
#gets s as a normal string
s[index]
#gets letter at index
s[start:stop:step]
#gets letters starting at start, up to but discluding stop, incrementing by step
s[index] = item
#sets letter at index to item
s.append(append)
#appends append to s
s.index(obj)
#returns the index of obj in s
s.insert(index, obj)
#inserts obj at index
s.replace(start, stop, obj)
#replaces the chars from stop to stop (discluding stop) with obj
del s[index]
#deletes the char at index
s1 + s2
s1 += s2
#adds stringbuffers together
Stack Class
Represents a stack
Importing:
from influence.list import stack
#or
from influence.list.stack import Stack
Initializing:
s = Stack()
Methods:
s.push(obj)
#puts an item to the top of the stack
s.pop()
#removes the top item in the stack
#raises stack.EmptyStackError if stack is empty
s.peek()
#gets the top item in the stack without removing it
#returns None if stack is empty
s.empty()
#returns True if s is empty
obj in s
#returns True if obj is in s, False otherwise
s.index(obj)
#returns the index of obj, -1 if not found
s.__len__() / len(s)
#returns the length of s
s.__str__() / str(s)
#returns s as a str
License
MIT License
Copyright (c) 2020 RandomKiddo
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
“Software”), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file influence-1.1a3.tar.gz
.
File metadata
- Download URL: influence-1.1a3.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48f8a6c46ba8a7754ad55c0b1580696410e5f48d2a12d87dc1d08bcfb083b996 |
|
MD5 | 6004b0d427c2ccf6d84a6168574bbf93 |
|
BLAKE2b-256 | 6205b27f29f11b08186a264989e1fb4fc0d68fa65155caafee5530502f759db2 |
File details
Details for the file influence-1.1a3-py3.8.egg
.
File metadata
- Download URL: influence-1.1a3-py3.8.egg
- Upload date:
- Size: 70.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aae05059676bd72f682c97ac304e9656fc9f5fb8d093ce750e37c252cbda5bdb |
|
MD5 | 7745514a7ded9a20a12bd82197c8b30b |
|
BLAKE2b-256 | 559018d2c4987154258073255f5dadfbde1165b226af2d963c4db312c48d7134 |
File details
Details for the file influence-1.1a3-py3-none-any.whl
.
File metadata
- Download URL: influence-1.1a3-py3-none-any.whl
- Upload date:
- Size: 29.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4592374ac93ff7aa1c7093d923cdeaab29fdc3b697ae9475b1bcd5181e0137a7 |
|
MD5 | e41ef4649d94956398a7f42e575cf2f9 |
|
BLAKE2b-256 | d01b938057f97f24d02ab54fdb51a09965132fb5f0f9a714172d5c8807e96a2d |