Skip to main content

A python module for cutting strings.

Project description

PyPI - Version PyPI - License PyPI - Downloads Publish PyPi CI

pycutroh

The pycutroh module is a simple string cutting module.

Table of contents

  1. Introduction
  2. Getting started
    1. Prerequisites
    2. Installation
  3. How to use
    1. How to import
    2. Using the module
    3. Using the cli
  4. Releasing
  5. License

Introduction

I've written this module to learn python and some python basics like using unittests, imports and how python modules/packets work.

This module is inspired by the linux bash command.

At the moment this module provides four functions, which can be used to manipulate strings. For further information see here: How to use

The cli interface for this module is now available.

Getting started

Prerequisites

  • Python installed
  • Operatingsystem: Linux or Windows, not tested on mac
  • IDE like VS Code, if you want to contribute or change the code

Installation

There are two ways to install this module depending on the way you work and the preinstalled modules:

  1. pip install pycutroh
  2. python -m pip install pycutroh

How to use

How to Import

You can import the module in two ways:

import pycutroh
  • This will import all functions. Even the ones that are not supposed to be used (helper functions).
from pycutroh import *
  • This will import only the significant functions, meant for using.

Using the module

Depending on the way you imported the module, the following examples look a bit different.

Example 1:

from pycutroh import *

print(get_letter_on_pos("This is a demonstration string.",0))

Result:

T

Example 2:

from pycutroh import *

print(get_letters_from_pos_to_pos("This is a demonstration string.",(0,4)))

Result:

This

Example 3:

from pycutroh import *

print(get_fields("This is a demonstration string.",(0,3)," "))

Result:

This demonstration

Example 4:

import pycutroh

print(pycutroh.get_fields_new_separator("This is a demonstration string.",(0,3)," ","|"))

Result:

This|demonstration

Using the cli

You can now use the cli of the pycutroh module. This cli is my first using the argparse module, so there might be adjustments in the future.

To show the help run the following command:

python -m pycutroh -h

Result:

usage: __main__.py [-h] [-s STRING] [-glop GETLETTERONPOS | -glbp GETLETTERSFROMPOSTOPOS GETLETTERSFROMPOSTOPOS | -glbfs GETLETTERSBEFORESIGN | -glas GETLETTERSAFTERSIGN | -glbs GETLETTERSBETWEENSIGNS GETLETTERSBETWEENSIGNS] {f} ...

positional arguments:
  {f}                   Get fields separated by specified delimiter.
    f                   Get fields by delimiter and join using same delimiter.

options:
  -h, --help            show this help message and exit
  -s STRING, --string STRING
  -glop GETLETTERONPOS, --getLetterOnPos GETLETTERONPOS
                        Letter on position to return.
  -glbp GETLETTERSFROMPOSTOPOS GETLETTERSFROMPOSTOPOS, --getLettersFromPosToPos GETLETTERSFROMPOSTOPOS GETLETTERSFROMPOSTOPOS
                        Get letter between positions.
  -glbfs GETLETTERSBEFORESIGN, --getLettersBeforeSign GETLETTERSBEFORESIGN
                        Get letters Before specified sign.
  -glas GETLETTERSAFTERSIGN, --getLettersAfterSign GETLETTERSAFTERSIGN
                        Get letters after specified sign.
  -glbs GETLETTERSBETWEENSIGNS GETLETTERSBETWEENSIGNS, --getLettersBetweenSigns GETLETTERSBETWEENSIGNS GETLETTERSBETWEENSIGNS
                        Get letters between specified signs.

Using a function:

python -m pycutroh f --getFields (0,1,2,3) --delimiter " " --newDelimiter ","

Result:

This,is,a,demonstration

Releasing

Releases are published automatically when a tag is pushed to GitHub.

# Create release variable.
$Release = "x.x.x"
# Create commit.
git commit --allow-empty -m "Release $Release"
# Create tag.
git tag -a $Release -m "Version $Release"
# Push from original.
git push origin --tags
# Push from fork.
git push upstream --tags

License

MIT

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

pycutroh-0.1.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

pycutroh-0.1.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pycutroh-0.1.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pycutroh-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7bf5b49fab6152dc3c4aa12b72bcffdb2e133b4718fc7245058ca0abe74d09dc
MD5 1928e83c19da134e7ea81febe9f16c18
BLAKE2b-256 91a658342157d9da3f082cbfe7239250a4a3c577beaf613156382ee858c6b865

See more details on using hashes here.

File details

Details for the file pycutroh-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pycutroh-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for pycutroh-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5b30eca15d6580e2fecc91095aae546a346e6894f30cbe5ae7e2d601b235dd37
MD5 e241618d3a7d4691b772b73d78423881
BLAKE2b-256 1f0fbe8e8452de8eeaffc6297233f1f3f3faae5ab52c0f7aeac6ff07e8f9eb04

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