Typer Library Word Count Tool

  • Share this:

Code introduction


This function creates a command-line tool using the Typer library. Users can input text through the command line, and the function will return the number of words in the text.


Technology Stack : Typer

Code Type : Command line tool

Code Difficulty : Intermediate


                
                    
from typer import Typer, Argument, Option

def count_words(text: str = Argument(..., help="输入的文本")) -> int:
    """计算输入文本中的单词数量。"""
    return len(text.split())                
              
Tags: