Skip to main content

Use this package to work with kor files

Project description



Kor Project

This repository contains the files of the Kor project with all the doc that you need

Changelogs

  • Added exemple.py

The Kor Project Goals

The kor project is desinged to store easlily data in file (.kor file) such as numbers, list, and many more ! You can define your own encoding method to encode your own object or varaible type.

Why use kor files ?

  • Kor files allows you to easily store data
  • Can easily be customized to suit your needs
  • Is very simple to use

Example

  1. First of all you'll need to import kor
import kor
  1. The you'll need to create your file object before working with it
my_file = kor.Kor(file_path="test_file.kor")
  1. Now you can use one one the module's method to do something with it, for instance we can add an author and a description
my_file.add_author(author="Koraku")  
my_file.add_desc(desc="This is a example file")

The content of the file :

*Author : Koraku  
*Desc : This is a example file
  1. Add more content !
my_file.encode(line_type='var', line=3, name="My_var", value="Hello, I'm a var content !", value_type="str")

Kor project documentation

List of all the method you'll need

File options

  • add_author(author) is used to add an author to your file
  • add_desc(desc) is used to add a description to your file
  • get_author() returns the author of the file
  • get_desc() returns the description of the file

Encoding and decoding

  • encode(line_type, line, name, value, value_type, custom_encoding=None, custom_line_type=None, custom_value_type=None) see the "Encode parameters description" section for further information

  • decode(custom_line_type=None, custom_decoding=None) see the "Decode parameters description" for further information

Others

  • reset() erase all the data in your file, irreversible
  • search(line_type, name) search in the file if a line has a certain name and returns [True, line_name, line_number] if found and [False, None, None] if not found

Encode parameters description

Line types

There are three line type by default :

  1. var is used to store str (string) or numbers
  2. list is used to store list or tuple
  3. custom is used to use your custom encoding method, see bellow for further information

Line

The first two lines of the files are dedicated to the file author and description, keep in mind that the first line starts at 0 not 1

Value

The value is what your line will contain, the type of the content must be specified with value_type

Value type

There are 2 value type by default :

  1. str for string
  2. numfor numbers (int, float...)

Custom_encoding/custom_line_type/custom_value_type

Used for custom encoding, see "How to : Custom encoding" section for further information

Decode parameters description

The only parameters that decode() takes are custom_line_type, custom_decoding & custom_separator which are both used for custom decoding, see "How to : custom decoding" section for further information.

Custom parameters

The Kor Project allows you to create your own encoding methods, in those two examples you will learn how to do so Also, see "example.py" in the github page

How to : custom encoding

  1. Firstly, import kor and create your file object
import kor

my_file = kor.Kor(file_path="test_file.kor")
  1. Secondly, create your object
class My_Object:  
    def __init__(self, name, language):  
        self.name=name
        self.language=language

my_test_object = My_Object(name="Obj", language="Python")
  1. Then you'll need to create one fuction for encoding, for instance :
def custom_encoding(line_type, name, value, value_type): 
	return f"{line_type} : {name} -> {value_type} -> {value.name},{value.language}\n"

Value is your instance of My_Object, name is the name of your line, line_type will be your custom line type and value type your custom value_type

  1. I highly recommend you to define thos variables to prevent spelling mistakes
custom_line_type = "Custom_Line"
custom_value_type = "Custom_Value"
  1. Now you can encode your object ! Use the encode() method as showed
my_file.encode(line_type="custom",  
	line=3, 
	name="My_Object_Name",  
	value=my_test_object, 
	value_type=None,  
	custom_encoding=custom_encoding,  
	custom_line_type=custom_line_type,  
	custom_value_type=custom_value_type)

You must set line_type to custom to use your custom encoding value is your instance of you object (step 2) custom_encoding should be set to your custom encoding fuction (step 3) custom_line_type & custom_value_type are used for you custom line and value type (step 4)

The result of the above code :

*Author : Koraku  
*Desc : This is a example file  

Custom_Line : My_Object_Name -> Custom_Value -> Obj,Python

How to : custom decoding

Repeat steps 1 & 2

  1. Create your custom decoding fuction
def custom_decoding(value_args):
	return My_Object(name=value_args[0], language=value_args[1])

value_args will be passed in your function, it represent a list with the value of you objetc parameters (in this exemple), here it is ['Obj', 'Python']

  1. Now decode your file with the decode() method
my_file.decode(custom_line_type=custom_line_type,
	custom_decoding=custom_decoding, 
	custom_separator=",")
  1. if you print the output of this method it will give
[('My_Object_Name', <__main__.My_Object object at 0x00000270B6579E48>)`]

We can print the name and the value of our object :

my_new_obj = my_file.decode(custom_line_type=custom_line_type,
	custom_decoding=custom_decoding, 
	custom_separator=",")[0][1]

print(my_new_obj.name, my_new_obj.language)

output :

Obj Python

Now you know how to encode and decode your own object ! 🙌🎉

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kor_project-0.0.2.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kor_project-0.0.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file kor_project-0.0.2.tar.gz.

File metadata

  • Download URL: kor_project-0.0.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.4

File hashes

Hashes for kor_project-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a9662447e986046d2573d5404138f1d0dbe06cd0f2e64b6fecae40802cb4b7f6
MD5 7ea550b2fb068f44f5314bf5febe397b
BLAKE2b-256 8344af5ffd7a1d4d6f34744cecf070c6b291100389f4593e8f31d02efa7a27b9

See more details on using hashes here.

File details

Details for the file kor_project-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: kor_project-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.4

File hashes

Hashes for kor_project-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 58f8b2cb76771c0797052a9c2dbdbeafd02c417c9ca391f6c3b0325302ef8574
MD5 a045b0197f725d20a266b8cd8646023b
BLAKE2b-256 41820784a99614779da4f24876db3d4f67c6361d0bcf774bad69fb33b656a421

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page