Skip to main content

A custom Python module collection

Project description

foxange

A collection of convenient Python utility functions for input, file handling, and list processing.


Functions Overview

Input Utilities (foxange.input)

  • collect_input
    Prompt for sequential user input; returns a list of the inputted values.

    from foxange.input import collect_input
    answers = collect_input("Enter your name: ", "Enter your age: ")
    # ['Alice', '30']
    
  • input_to_file
    Write specified strings to a file (also available in foxange.file).

    from foxange.input import input_to_file
    input_to_file("hello", "foxange", path="test.txt")
    # test.txt will contain:
    # hello
    # foxange
    
  • sanitize_input
    Remove multiple substrings from text.

    from foxange.input import sanitize_input
    print(sanitize_input("hello", "e", "o"))  # "hll"
    
  • numeric_input
    Get input and return it only if length is within specified bounds.

    from foxange.input import numeric_input
    val = numeric_input("Type (2-4 chars): ", 2, 4, notvalid="N/A")
    
  • choice_input
    Present choices and get the user’s selection (may need adjustment for your use-case).

    from foxange.input import choice_input
    print(choice_input("Pick one:", ["a", "b", "c"], "Choose: "))
    
  • confirm
    Simple yes/no user prompt returning True, False, or None.

    from foxange.input import confirm
    if confirm("Continue?"): 
        print("Confirmed!")
    

File Utilities (foxange.file)

  • input_to_file
    See above.

  • read_lines
    Read lines from a file into a list (strips newlines by default).

    from foxange.file import read_lines
    print(read_lines("text.txt"))  # ["line 1", "line 2"]
    
  • write_lines
    Write a list of strings to a file, one per line.

    from foxange.file import write_lines
    write_lines("out.txt", ["foo", "bar"])
    
  • tail / head
    Get the last/first N lines of a file.

    from foxange.file import tail, head
    print(tail("log.txt", 5))
    print(head("log.txt", 5))
    
  • safe_read_json / safe_write_json
    Robust JSON file read/write with error fallback.

    from foxange.file import safe_read_json, safe_write_json
    data = safe_read_json("settings.json", default={})
    safe_write_json("settings.json", {"theme": "dark"})
    
  • get_file_size
    Return the file size (bytes or human-readable).

    from foxange.file import get_file_size
    print(get_file_size("large.bin", human_readable=True))  # "1.1 MB"
    
  • ensure_dir
    Ensure a directory exists (create if needed).

    from foxange.file import ensure_dir
    ensure_dir("output/")
    
  • atomic_write
    Safely write to a file using a temporary buffer.

    from foxange.file import atomic_write
    atomic_write("a.txt", "data")
    
  • find_files
    Recursively find files matching a pattern.

    from foxange.file import find_files
    print(find_files(".", "*.py"))
    

List Processing Utilities (foxange.list_proce)

  • remove
    Remove all elements satisfying the given condition.

    from foxange.list_proce import remove
    odds = remove([1, 2, 3, 4], lambda x: x % 2 == 0)  # [1, 3]
    
  • unique
    Return unique entries from a list.
    Note: fix suggested—code may not deduplicate as expected.

    from foxange.list_proce import unique
    print(unique([1, 1, 2]))  # [1, 2]
    
  • rotate
    Circularly rotate a list right by n positions.

    from foxange.list_proce import rotate
    print(rotate([1, 2, 3, 4], 2))  # [3, 4, 1, 2]
    

How to Use

Import the specific function you need:

from foxange.input import collect_input
from foxange.file import read_lines
from foxange.list_proce import unique

Explore the src/foxange/ directory for all available modules and features!


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

foxange-0.3.2.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

foxange-0.3.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file foxange-0.3.2.tar.gz.

File metadata

  • Download URL: foxange-0.3.2.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for foxange-0.3.2.tar.gz
Algorithm Hash digest
SHA256 357a2a8a4cc4f532a4fec16b42d5b73c30221110197b6c62989905921d2b2e6d
MD5 95cc568b67ab25081c08b17ce9290bd9
BLAKE2b-256 adc0f0a2b70642bcabf51d97bde2d7da5b0d89679bfb286cf3b64ea3b4352112

See more details on using hashes here.

File details

Details for the file foxange-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: foxange-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.2

File hashes

Hashes for foxange-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e0579e6e3c52e419e47caf2e2348cdbb55a7bb6133ee2c1310868f84dfe97524
MD5 c29ab53db475fb85ca3ee8fa3a537f62
BLAKE2b-256 584a7e0854be5236bafc50b034c285c404ba3aca14b8eb397e2db34df1b34be2

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