Cope 2.5.0
My personal "standard library" of all the generally useful code I've written for various projects over the years
Loading...
Searching...
No Matches
Cope.misc Namespace Reference

A bunch of miscellaneous functions and classes that might be useful. More...

Classes

class  RedirectStd
 

Functions

list available (*args, null=None)
 Of the parameters passed, returns the parameters which are not null
 
bool only1 (*args, null=None)
 Returns true only if there is only 1 non-null parameter.
 
float interpret_percentage (Union[int, float] percentage)
 
def percent (Union[int, float] percentage)
 Usage: if (percent(50)): <code that has a 50% chance of running> NOTE: .5 works as well as 50.
 
bool randbool ()
 Returns, randomly, either True or False.
 
def close_enough (a, b, tolerance)
 Returns True if a is within tolerance range of b.
 
int closest (SupportsInt target, Iterable[SupportsInt] compare, index=False)
 Finds the value in compare that is closest to target.
 
int furthest (SupportsInt target, Iterable[SupportsInt] compare, index=False)
 Finds the value in compare that is furthest from target.
 
bool isPowerOf2 (int x)
 Returns true if x is a power of 2.
 
bool between (target, start, end, left_open=False, right_open=False)
 Returns True if target is between start and end.
 
str insert_str (str string, int index, str inserted)
 Returns the string with inserted inserted into string at index
 
def constrain (val, low, high)
 Constrains val to be within low and high
 
SupportsAbs translate (SupportsAbs value, SupportsAbs from_start, SupportsAbs from_end, SupportsAbs to_start, SupportsAbs to_end)
 Proportionally maps value from being within the from range to the to range.
 
def frange (float start, float stop, float skip=1.0, int accuracy=10000000000000000)
 
bool confirm (str prompt='Continue?', bool quit=False, str quit_msg='Exiting...', bool return_if_invalid=False, bool include_YN=True)
 Promt the user to confirm via terminal whether to continue or not.
 
str cat_file (str f)
 Simply return whatever is in the given file path.
 
str umpteenth (int i)
 Return the string name, i.e.
 
str grade (Union[float, int] percentage)
 This returns the letter grade given, based on the percentage you have in a class NOTE: This is one scale, that represents general accuracy.
 
bool isiterable (obj, bool include_str=True)
 Returns True if you can iterate over obj.
 
def ensure_iterable (Iterable iter, type cast=list, bool ensure_cast_type=True)
 Ensures that iter is an iterable, if it isn't already.
 
def ensure_not_iterable (Iterable iter)
 Ensures that iter is not an iterable, IF iter only has one element.
 
def cp (thing=None, int rnd=3, show=False, not_iterable=True, evalf=True)
 Quick shortcut for notebooks for copying things to the clipboard in an easy way.
 
def in_IPython (return_instance=True)
 
list flatten (Iterable iter, bool recursive=True)
 Denest either 1 or all lists inside of iter into one big 1 dimentional list.
 
dict invert_dict (dict d)
 Returns the dict given, but with the keys as values and the values as keys.
 
def run_notecards (dict cards)
 A quick function for helping you practice notecards.
 

Variables

def ensureIterable = ensure_iterable
 
def ensureNotIterable = ensure_not_iterable
 

Detailed Description

A bunch of miscellaneous functions and classes that might be useful.