Skip to main content

Small utils for Python

Project description

Language

utilspy

PyPI PyPI - License PyPI - Python Version

Small utils for python


Installation

Package Installation from PyPi

$ pip install utilspy-g4

Package Installation from Source Code

The source code is available on GitHub.
Download and install the package:

$ git clone https://github.com/Genzo4/utilspy
$ cd utilspy
$ pip install .

Utils

  • add_ext

Add extension to path.

Support Windows and Linux paths.

from utilspy_g4 import add_ext

path = '/test/test.png'
ext = '2'
new_path = add_ext(path, ext)     # new_path = '/test/test.2.png'
  • del_ext

Del extension from path.

Support Windows and Linux paths.

from utilspy_g4 import del_ext

path = '/test/test.png'
new_path = del_ext(path)     # new_path = '/test/test'

path = '/test/test.2.png'
new_path = del_ext(path)     # new_path = '/test/test.2'

path = '/test/test.2.png'
new_path = del_ext(path, 2)     # new_path = '/test/test'
  • templated_remove_files

Remove files by template

from utilspy_g4 import templated_remove_files

templated_remove_files('/tmp/test_*.txt')
  • get_ext

Get extension from path.

Support Windows and Linux paths.

from utilspy_g4 import get_ext

path = '/test/test.png'
ext = get_ext(path)     # ext = 'png'

path = '/test/test.jpeg.png'
ext = get_ext(path)     # ext = 'png'

path = '/test/test.jpeg.png'
ext = get_ext(path, 2)     # ext = 'jpeg'

path = '/test/test.jpeg.png'
ext = get_ext(path, 0)     # ext = ''
  • int_to_2str

Convert integer to 2 chars string with 0.

from utilspy_g4 import int_to_2str

time = f'{int_to_2str(2)}:{int_to_2str(23)}:{int_to_2str(5)}' # time = '02-23-05'
  • get_files_count

Get files count from template.

Support Windows and Linux paths.

from utilspy_g4 import get_files_count

get_files_count('/tmp/test_*.txt')
  • date_template

Returns the date string representation template.

from utilspy_g4 import date_template

template = date_template('2022/10/28')  # template = '%Y/%m/%d'
  • to_date

Converts various representations of a date to the date format of the standard datetime library.

Currently supported:

  • date
  • datetime
  • str ('2022/01/02', ...)
from utilspy_g4 import to_date

d = to_date('2022/10/28')

# type(d) == date
# d.year = 2022
# d.month = 10
# d.day = 28

Changelog


Language

utilspy

PyPI PyPI - License PyPI - Python Version

Небольшие утилиты для Python.


Установка

Установка пакета с PyPi

$ pip install utilspy-g4

Установка пакета из исходного кода

Исходный код размещается на GitHub.
Скачайте его и установите пакет:

$ git clone https://github.com/Genzo4/utilspy
$ cd utilspy
$ pip install .

Утилиты

  • add_ext

Добавляет дополнительное расширение файла перед его последним расширением.

Обрабатывает как Windows пути, так и Linux.

from utilspy_g4 import add_ext

path = '/test/test.png'
ext = '2'
newPath = add_ext(path, ext)     # newPath = '/test/test.2.png'
  • del_ext

Удаляет одно или несколько расширений файла

Обрабатывает как Windows пути, так и Linux.

from utilspy_g4 import del_ext

path = '/test/test.png'
new_path = del_ext(path)     # newPath = '/test/test'

path = '/test/test.2.png'
new_path = del_ext(path)     # newPath = '/test/test.2'

path = '/test/test.2.png'
new_path = del_ext(path, 2)     # newPath = '/test/test'
  • templated_remove_files

Удаление файлов по шаблону

Обрабатывает как Windows пути, так и Linux.

from utilspy_g4 import templated_remove_files

templated_remove_files('/tmp/test_*.txt')
  • get_ext

Возвращает расширение файла. Можно указать какое по счёту расширение надо вернуть.

Обрабатывает как Windows пути, так и Linux.

from utilspy_g4 import get_ext

path = '/test/test.png'
ext = get_ext(path)     # ext = 'png'

path = '/test/test.jpeg.png'
ext = get_ext(path)     # ext = 'png'

path = '/test/test.jpeg.png'
ext = get_ext(path, 2)     # ext = 'jpeg'

path = '/test/test.jpeg.png'
ext = get_ext(path, 0)     # ext = ''
  • int_to_2str

Преобразует число в строку из двух символов. Если число состоит из одной цифры, то спереди добавляется '0'.

from utilspy_g4 import int_to_2str

time = f'{int_to_2str(2)}:{int_to_2str(23)}:{int_to_2str(5)}' # time = '02-23-05'
  • get_files_count

Возвращает количество файлов в папке по шаблону.

Обрабатывает как Windows пути, так и Linux.

from utilspy_g4 import get_files_count

get_files_count('/tmp/test_*.txt')
  • date_template

Возвращает шаблон строкового представления даты.

from utilspy_g4 import date_template

template = date_template('2022/10/28')  # template = '%Y/%m/%d'
  • to_date

Преобразует различные представления даты в формат date стандартной библиотеки datetime.

На данный момент поддерживается:

  • date
  • datetime
  • str ('2022/01/02', ...)
from utilspy_g4 import to_date

d = to_date('2022/10/28')

# type(d) == date
# d.year = 2022
# d.month = 10
# d.day = 28

Changelog

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

utilspy_g4-2.2.0.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

utilspy_g4-2.2.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file utilspy_g4-2.2.0.tar.gz.

File metadata

  • Download URL: utilspy_g4-2.2.0.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for utilspy_g4-2.2.0.tar.gz
Algorithm Hash digest
SHA256 07a3e472c6585b4dc47eb4cc1a97c0d669aef9bff65658e48bab36ebe9599a76
MD5 ac3b945490d441412022cb18f6ced41f
BLAKE2b-256 0f1b6036382213a3d5c211e0a54e61daed728c45d8add91f5071409afe3032ab

See more details on using hashes here.

File details

Details for the file utilspy_g4-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: utilspy_g4-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for utilspy_g4-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7feafcb926e77e871ab910de57ed871227fafb0077ae90e9771416febb7d043d
MD5 83caf3beca7746b8fdfcfdcf9401fa3c
BLAKE2b-256 ffaff6ab8954c7ec2b8f0e6a20c71d92a67662fb36a5610961c54f6c100200e9

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