Skip to main content

Easily Structuring Data

Project description

CSV and TXT Writer Library

This library provides functionality for writing data to CSV and TXT files.

Functions

write_to_csv(data, filename, labels='None')

This function takes two lists and adds them to a CSV file line by line.

If you choose to add labels, it will add data based on how many label rows there are.

  • data: Multidimensional list of data for each line.
  • labels: List of labels for each row (optional).
  • filename: Name of file.

write_to_txt(data, filename, labels='None', char_separator='None')

This function takes two lists and adds them to a TXT file line by line.

If you choose to add labels, it will add data based on how many label rows there are.

If you choose to add a character separator instead of the default ,, it will add that character in between elements.

  • data: Multidimensional list of data for each line.
  • labels: List of labels for each row (optional).
  • filename: Name of file.
  • char_separator: Character separator (optional).

Example Usage

from textscribe import scribe

# Example 1: Writing to a CSV file with labels
labels = ['Name', 'Age', 'City']
data = [['John', 25, 'New York'], ['Jane', 30, 'Los Angeles']]
filename = 'example.csv'
scribe.write_to_csv(data, filename, labels=labels)

# Example 2: Writing to a TXT file with labels and a custom separator
labels = ['Name', 'Age', 'City']
data = [['John', 25, 'New York'], ['Jane', 30, 'Los Angeles']]
filename = 'example.txt'
scribe.write_to_txt(data, filename, labels=labels, char_separator='/')

extract_data_by_label_csv

This function extracts data from a CSV file under a specified label.

def extract_data_by_label_csv(file_name, label):

Args

  • file_name (str): The name of the CSV file to read.
  • label (str): The label to look for in the CSV file.

Returns

  • list: A list containing all the data under the given label.

Raises

  • ValueError: If the label is not found in the CSV file.
  • Exception: If the file name is not a .csv file.

extract_data_by_label_txt

This function extracts data from a TXT file under a specified label.

def extract_data_by_label_txt(file_name, label, delimiter=','):

Args

  • file_name (str): The name of the TXT file to read.
  • label (str): The label to look for in the TXT file.
  • delimiter (str): The character used to separate elements in the TXT file. Default is ','.

Returns

  • list: A list containing all the data under the given label.

Raises

  • ValueError: If the label is not found in the TXT file.
  • Exception: If the file name is not a .txt file.

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

textscribe-0.0.7.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file textscribe-0.0.7.tar.gz.

File metadata

  • Download URL: textscribe-0.0.7.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for textscribe-0.0.7.tar.gz
Algorithm Hash digest
SHA256 fbf275df1ff4056c8ec8fa9b1767b87124b79ed0ee133fc4ddc9bb4fdf17420e
MD5 318295f853c6f1d04e63f2de0492d390
BLAKE2b-256 69b064332222ad1231f22b93f3e54b22d0c36e80282f15affb51f173ae4f6677

See more details on using hashes here.

Supported by

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