View on GitHub

usefulpy

A module filled with many useful functions and modules in various subjects.

Usefulpy

Usefulpy Logo

Filled with simple resources and modules for a cleaner looking program, Usefulpy is a module filled with many useful functions and modules in various subjects geared to cut down and simplify some little bits of code that can become messy or repetitive.

So instead of checking, say

float(x) == int(float(x))

You can check it as

is_integer(x)

Which calls

def is_integer(s):
    '''Check if an object is an integer can be turned into an integer without
losing any value'''
    try: return int(float(s)) == float(s)
    except: return False

Simple, but works well and can be used in a variety of situations. This also allows you to quickly write the check without having to go back and make a module, interupting your flow of thought; or without marking it down for later creation, and then forget it (happens to me all the time).

While I would recommend getting aquainted with the code by sifting through it by hand, here is a quick introduction:

Sections

validation

Validation includes various tools for getting input and preparing clean output, as well quick checks for types. The main idea is to check whether something fits in a category.

A couple of its most important sections:

Integer/Float Tools:

Custumizable Tools:

Some of the Other Tools:

and more…

mathematics

Contains a lot of useful mathematical stuff.

The mathematics section is divided into several programs, though from usefulpy.mathematics import * imports all of the functions from all of them.

These are the smaller programs that are not imported with the mathematics __init__.

nmath

nmath (new math) recreates and combines the cmath and math modules.

Most Important parts

basenum

A basenum class:

>>> x = basenum('3a2', 16)
>>> x
3a2₁₆
>>> y = x/2
>>> y
1d1₁₆
>>> float(x)
930.0
>>> int(y)
465
>>> basenum('101', 2)
101
>>> _.convert(4)
11
>>> _+basenum('10.1', 2)
13.2
>>> float(_)
7.5
>>> 

quaternion

A quaternion class:

>>> quaternion(1, 2, 3, 4)
(1+2i+3j+4k)
>>> quaternion(1+3j)
(1+3j)
>>> 

This class has a full range of functions and methods implimented… have fun!

formatting

Data

Important Functions

Multline class

Formatting includes a multline class, still a bit confusing and in its early stages but, cocinates and deals with strings that can span various lines as if they were single line/matrix.

' 3 '   '12'   ' 3 12'
'---' + '--' = '-----'
' 4 '   '13'   ' 4 13'

Now supports some pretty neat slicing.

(of course, in the IDLE this would look different)

Decorators

Decorators just has a few decorators. Nothing much to see here.

IDE

A usefulpy IDE, in progress

>>> import usefulpy
>>> usefulpy.ide()
In [0] : 1+1i-2j+4k

Out[0] : (1+1i-2j+4k)

In [1] : cos(tau/4)

Out[1] : 6.123233995736766e-17

In [2] : _0

Out[2] : (1+1i-2j+4k)

In [3] : _1

Out[3] : 6.123233995736766e-17

In [4] : 1+i+j+k

Out[4] : (1+1i+1j+1k)

In [5] : cos(_)

Out[5] : (1.5747529115583139-1.3300177322185731i-1.3300177322185731j-1.3300177322185731k)

In [6] : sin(__)

Out[6] : (2.452532348883716+0.8539945649192698i+0.8539945649192698j+0.8539945649192698k)

In [7] : __**2+_**2

Out[7] : (0.9999999999999964)

In [8] : ___

Out[8] : (1.5747529115583139-1.3300177322185731i-1.3300177322185731j-1.3300177322185731k)

In [9] : _==_5

Out[9] : True

In [10] : Out[8]

Out[10] : (1.5747529115583139-1.3300177322185731i-1.3300177322185731j-1.3300177322185731k)

In [11] : In[0]

Out[11] : '1+1i-2j+4k'

In [12] : 1.0

Out[12] : 1

In [13] : __defaults__['#'] = float

In [14] : 1

Out[14] : 1.0

In [15] : acos(1)

Out[15] : 0

In [16] : arccos(1)

Traceback (most recent call last):
  File "/Users/mac/Documents/usefulpy/IDE/usefulpy_IDE.py", line 95, in ide
    exec(corrected_input, namespace)
  File "<string>", line 1, in <module>
NameError: name 'arccos' is not defined

In [16] : a = 2

In [17] : a

Out[17] : 2 

In [18]: quit()

{'a':2}
>>> #returns dictionary of scope.

gui

Includes a wrapper around tkinter, which can be frustrating to work with, to make it simpler and a set of programs called py3d, for a 3d space in the built-in tkinter canvas.

py3d

A pure-python 3d system… I’d like to shift some of this into C or C++

Rotating Cube

Versions

Versions include 0.0.0, 0.0.1, 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.2.0

Usefulpy 0.2.0:

mini_usefulpy_logo