Skip to main content

bios is a library which helps you to read and write data to determined type of files.

Project description

bios

  • 'bios' is a python library which helps you for operations of I/O.
  • You can read determined type of files and assign the content of the files to the best suitable data type for these contents.
  • If it is required, developer should handle the exception handling issues.

Install and Import

pip install bios

import bios

Supported Files

  • JSON Files
    • Can be assigned to data types of string, list or dict.
  • YAML Files
    • Can be assigned to data types of string, list or dict.
  • CSV Files
    • Can be assigned to data types of string or list.
  • Other Files
    • Can be assigned to data type of string.

Operations and Using

Reading

You can read the file using read function of bios. If you will not give any file type, system can determined the file types showing in the below and assign the content of the files to suitable data_types.

content1 = bios.read('file.txt')
content2 = bios.read('file.json')
content3 = bios.read('file.yaml')
content4 = bios.read('file.csv')
content4 = bios.read('file.csv', delimiter=';')
content5 = bios.read('file.yml')
content6 = bios.read('file')

# Type of content1 and contend6 is string
# Type of content2, content3 and content5 is dict or list
# Tyoe of content4 is list
  • Standart File

You can read the content of a file and assign it into a string.

content = bios.read('file.txt', file_type='standart')
  • JSON File

You can read the content of a JSON file and assign it into a dict or list object.

content = bios.read('file.json', file_type='json')

Type of the content could be 'list' or 'dict'

  • YAML File

You can read the content of a YAML file and assign it into a dict or list object.

content = bios.read('file.yaml', file_type='yaml')
content = bios.read('file.yaml', file_type='yml')

Type of the content could be 'list' or 'dict'

  • CSV File

You can read the content of a CSV file and assign it into a list. Default delimiter is comma ' , '.

content = bios.read('file.json', file_type='csv')
content = bios.read('file.json', file_type='csv', delimiter=';')

Type of the content could be 'list'

Writing

You can write your 'data' object to a file. If you will not give a specific file a file type, file type is determined according to the file name.

bios.write('file.txt', data1)
bios.write('file.json', data2)
bios.write('file.yaml', data3)
bios.write('file.csv', data4)
bios.write('file.csv', data4, delimiter=';')
bios.write('file.yml', data5)
bios.write('file', data5)

# data1 and data5 must be a string
# data2, data3 and data5 must be a dict or list object
# data4 must be a list object
  • Standart File

You can write a string object to any file giving a file type as 'standart'

 bios.write('file.txt', data, file_type='standart')
  • JSON File

You can write a list or dict object to any file giving a file type as 'json'

 bios.write('file.json', data, file_type='json')
  • YAML File

You can write a list or dict object to any file giving a file type as 'yaml' or 'yml'

 bios.write('file.yml', data, file_type='yaml')
  • CSV File

You can write a list object to any file giving a file type as 'standart'

 bios.write('file.csv', data, file_type='csv')
 bios.write('file.csv', data, file_type='csv', delimiter=';')

You can use the parameter of 'delimiter' for separating the contents from each other.

Appending

You can append or add a content to an existing file. This function is available for only text files or csv files.

bios.append('file.txt', data)
bios.append('file.txt', data, line=2)
bios.append('file.txt', data, delimiter=';')
bios.append('file.csv', data, line=2, delimiter=';')

Line is assumed that starting from the value of 1

  • Standart File

You can append a string object to a existing or nonexistent file. If you don't give a line parameter, bios would append the content after the end of the file.

 bios.append('file.txt', data, file_type='standart')
 bios.append('file.txt', data, file_type='standart', line=2)
  • CSV File

You can append a list object to a existing or nonexistent file. If you don't give a line parameter, bios would append the content after the end of the file.

 bios.append('file.csv', data, file_type='csv')
 bios.append('file.csv', data, file_type='csv', line=2)

Example

import bios
content = bios.read('files/my_file.csv')
second_row = content[1]
for single_column in second_row:
    print(single_column)

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

bios-0.1.2.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file bios-0.1.2.tar.gz.

File metadata

  • Download URL: bios-0.1.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.2

File hashes

Hashes for bios-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bccfc24011b6a631a6edeef1069551a4ecaaff7b3ed50a6221a68075850500e9
MD5 f2668fd4f99ad590fc1a2c4a080ab1ed
BLAKE2b-256 b9a0368aac80c0ce24e014854621550bb802b82eb4e9c33d945866117ddc944e

See more details on using hashes here.

Supported by

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