An util package that includes features from other languages' stdlib.
An util package that includes algorithms, functions and IO similar to that of other languages' standard library.
Installation with pip is recommended.
pip install oven
Table of Contents
- Standard I/O
The stdio package includes convient functions to redefine basic I/O.
from oven.stdio import *
The stdio session is required in order to call any I/O functions. A session is created as such:
set_io(IO_STREAM, 'path/to/file', METHOD)
The IO_STREAM can be any of:
- stdio.FILE: Redirect the IO stream to a file
- stdio.CONSOLE: Redirect the IO stream to the console
The METHOD can be any of:
- r : Read from a file
- w : Write to a file, create/override if nessesary
- a : Append to a file, create if nessesary
Method w overrides the file and dump all output from the session, while a append all output from the session to the end of the file.
If the IO_STREAM is set to CONSOLE, then the path argument will be ignored.
Note that the stdio session is created on the global scope, therefore one session will always suffice for one method of IO action.
An example is given below. This code reads a line of input from a file and print it to the screen.
from oven.stdio import * set_io(FILE, 'text.in', 'r') set_io(CONSOLE, None, 'w') text = cin() cout(text)
Despite the name, the cin/cout also applies to file IO.
cin() # Read one line. cout('Hello World') # Write. Note that \n is not added at the end.
The Pointer package includes a pointer object.
from oven.pointer import Pointer
A Pointer is created as such:
ptr_1 = Pointer() ptr_2 = Pointer(INIT_VALUE)
Getting value from pointer:
value = ptr()
Assigning value to pointer:
The structs package features some data structures.
from oven.structs import *
from oven.structs import Stack
The Stack class is a subclass of python's list, its methods are:
- push : Push a value to the stack
- pop : Remove and return the ending element of the stack
from oven.structs import Queue
The Queue class is a subclass of python's list, its methods are:
- push : Push a value to the queue
- pop : Remove and return the starting element of the queue
from oven.structs import Tree
The Tree class is a recursive node of a tree. The value of the node can be assigned either in the constructor or by calling the value attribute (variable).
# Both nodes are tree nodes with the value 42 node_1 = Tree(42) node_2 = Tree() node_2.value = 42
A child can be added to a node by calling the addChild method and passing the child as the parameter. The children of a node can be accessed by calling the children attribute (variable).
Other methods include:
- dfs : Returns a list of the tree's nodes in depth first search order.
- bfs : Returns a list of the tree's nodes in breadth first search order.
from oven.structs import BinaryTree
node.left() # Returns the left node node.right() # Returns the right node node.left(newNode) # Sets the left node node.right(newNode) # Sets the right node
Due to this, the addChild method is removed.
All other methods are identical to that of the Tree class except the dfs method, which is tweaked so that the calling of it becomes:
The MODE can be any of:
All of the above modes are imported as such:
from oven.structs import PREORDER, INORDER, POSTORDER
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size oven-0.1.0-py3-none-any.whl (8.3 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size oven-0.1.0.tar.gz (5.3 kB)||File type Source||Python version None||Upload date||Hashes View|