Skip to main content

naturalsize

A Python toolkit for getting human-readable size of file and more

History

Originally designed only to return the human-readable size of a file,
naturalsize has developed itself to a Python toolkit with many useful functions.

Installation

Using pip

You can install naturalsize via pip using

  • in a commandline:

  • py -m pip install naturalsize
    

  • in a python script:

  • import os
    os.system('py -m pip install naturalsize')
    

    Usage

    naturalsize has many functions:

  • about() returns information about your release
  • nsize returns the human-readable filesize:
    naturalsize.nsize(556677)
    

    returns the size of a 556677 B large file.
    The args are:
    size for the files size in B
    comma for the rounding of the size (default: 2)
    base2 uses 1024 instead of 1000 as the base for the size (default: True)
    names as a list of names you give to file size units (default: ["B", "KB", "MB", "GB", ...])

  • randprinter prints random signs the following:
    naturalsize.randprinter(2000)
    

    This prints 2000 random signs.
    Args are:
    numb for the number of signs (default: 1000)
    signs as the list signs are chosen from (default: ["a", "b", "c", ...])

  • randprinter_ returns a callable randprinter object with the given specifications
  • special_starter waits for a given time and returns whether the user pressed Ctrl+c in this time:
    naturalsize.special_starter(100000000)
    

    passes 100 000 000 times and returns then False if the user hasn't interrupted the process.
    True is returned if the user interrupted.
    Args are:
    numbThe number the program passes before returning False (default: 150000000)

  • isInt returns whether a given object is an integer or a float, if this is accepted via the acceptFloat arg
  • listToInt sums up all integer or float, if this is accepted via the acceptFloat arg, and returns this
    Note that the acceptFloat arg is False by default.
  • reverse inverses the given boolean
  • replStr replaces a part of a string the following:
    naturalsize.replStr(1, "adc", "b")
    

    returns 'abc' as it replaces the value at index of a string with another string.
    The args are:
    index for the index the replacement is to be at (default: 0)
    strObj as the string replaced in (default: 'a')
    setIn as the string set in the other string (default: 'b')

  • replStrPassage replaces a passage of a string using the above function the following:
    naturalsize.replStrPassage(1, 2, "adec", "b")
    

    returns 'abc' as it replaces the values from indexstart to indexend of a string with another string.
    The index arg is split up into indexstart and indexend args
    for the begin and the end of the to-be-replaced passage (default: 0/1).

    More coming soon...

  • Release files for naturalsize 1.0.17

    For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

    Source distribution (sdist)

    Source distribution for naturalsize 1.0.17
    File Size Uploaded
    naturalsize-1.0.17.tar.gz 4.7 kB Details

    Built distribution (wheel)

    Table of built distributions (wheels) for naturalsize 1.0.17
    File Interpreter ABI Platform
    naturalsize-1.0.17-py3-none-any.whl Python 3 none any Details

    Total release size:9.8 kB

    Release files / naturalsize-1.0.17.tar.gz

    Download URL naturalsize-1.0.17.tar.gz
    Size 4.7 kB
    Tags Source
    SHA-256 checksum
    How to use checksums
    bd893192bd4e4c3167a4f000fb4f5c02ce154e7a5a84a040f58a80058f9139e2
    BLAKE2b-256 checksum
    How to use checksums
    8ded0e99d73d3b3c60b3d77698621025ca38cce98df150d6ff18c1cb227afe4d
    Upload date
    Uploaded using Trusted Publishing?
    What is trusted publishing?
    No
    Uploaded via twine/4.0.0 CPython/3.11.0

    Release files / naturalsize-1.0.17-py3-none-any.whl

    Download URL naturalsize-1.0.17-py3-none-any.whl
    Size 5.1 kB
    Tags Python 3
    SHA-256 checksum
    How to use checksums
    5b2e21fd83eb5941dfda0d08c9bc429c8827d9c5dcfef3b0774d17580aa0c8b1
    BLAKE2b-256 checksum
    How to use checksums
    a3fc5f4c9cb8f5a3dc57fca0b3caa9f8a2fd75166b48902091d31f4cd4da7a5f
    Upload date
    Uploaded using Trusted Publishing?
    What is trusted publishing?
    No
    Uploaded via twine/4.0.0 CPython/3.11.0

    Release history Release notifications | RSS feed

    This release

    1.0.17 This release

    2 release files

    1.0.16

    2 release files

    1.0.12

    2 release files

    1.0.11

    2 release files

    1.0.10

    2 release files

    1.0.9

    2 release files

    1.0.8

    2 release files

    1.0.7

    2 release files

    1.0.6

    2 release files

    1.0.5

    2 release files

    1.0.4

    2 release files

    1.0.3

    2 release files

    1.0.2

    2 release files

    1.0.1

    2 release files

    1.0.0

    2 release files

    Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page