Skip to main content

A command-line tool for counting unique characters in strings or files

Project description

🖥️ Task 4 CLI Character Counter

A command-line interface application developed as part of the Foxminded course. This code provides a convenient command-line tool for counting unique characters in strings or files, with error handling and performance optimization through memoization.

📋 Requirements

Python 3.10+ Pytest Coverage

🚀 Installation

git clone https://git.foxminded.ua/foxstudent106775/task_4_cli.git

💻 Usage

How to Run

  1. Open your Terminal/Command Prompt: Navigate to the directory containing unique_chars.py using the cd command.

  2. Run the Application:

    Using a String Input:

    python unique_chars.py --string "your string here"
    

    Examples:

    python unique_chars.py --string "hello world"
    python unique_chars.py --string "AaBbCc123"
    

    Using a File Input:

    python unique_chars.py --file "your_file.txt"
    

    Examples:

    # Local file
    python unique_chars.py --file "my_text.txt"
    
    # Absolute path (Unix/Linux)
    python unique_chars.py --file "/path/to/your/file/data.txt"
    
    # Absolute path (Windows)
    python unique_chars.py --file "C:\folder\file.txt"
    

🎯 Available Options

Option Description
--string "string" Specifies the input string to be analyzed (must be in double quotes)
--file "file_path" Specifies the path to the text file to be analyzed (must be in double quotes)

📝 Expected Outputs

✅ Successful Execution

Number of unique characters: [number]

Where [number] is the count of characters that appear only once in the input.

❌ Error Outputs

Error Type Message Description
ValueError No input provided. Use --string or --file No input option provided
FileNotFoundError File not found: [file_path] Specified file doesn't exist
IOError Error reading file: [error_message] File reading problems
Exception Error: [error_message] Other unexpected errors

📊 Example Scenarios

  1. Counting unique characters in a string:

    $ python unique_chars.py --string "aabbcde"
    Number of unique characters: 3  # (c, d, and e appear once)
    
  2. Counting unique characters in a file:

    $ python unique_chars.py --file "data.txt"  # data.txt contains "122345"
    Number of unique characters: 3  # (1, 3, and 5 appear once)
    

📁 Project Structure

task_4_cli/
├── CollectionFramework/
│   ├── collection.py
│   └── __init__.py
├── tests/
│   ├── __init__.py
│   └── test_collect.py

🧪 Testing

Run tests using pytest with coverage:

pytest --cov=CollectionFramework tests/

👨‍💻 Author

Volodymyr Savchenko

📄 License

[MIT License]


Made in Python

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

unique_chars_counter_vs-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

unique_chars_counter_vs-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file unique_chars_counter_vs-0.1.0.tar.gz.

File metadata

  • Download URL: unique_chars_counter_vs-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for unique_chars_counter_vs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 150cd0113cd3ba0d6a89f5d083120eec768d89ceb08c00d1a6613693a1e0ecf6
MD5 629f8d1e11df4b0e2f7fc4a24d8b098c
BLAKE2b-256 08e987aafd5f8e5b5f795e9cb827cff05829b620561eb5795d84a53742ca9c15

See more details on using hashes here.

File details

Details for the file unique_chars_counter_vs-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for unique_chars_counter_vs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c7aa5f0f0429ff644a8a927a50afdc721ae3cc82547ee899a26585ba8609f47
MD5 b0c13971133c1bc9a8b3aa56aa3aef2d
BLAKE2b-256 1e7bd92eee863df58c8348003aa9371f4d95f0ac0ac12f7575e3a347e6876ebe

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