clipcount
This is a Python package that reads text from the clipboard and outputs the character count.
Setup
Install via pip:
pip install clipcount
Handling "Warning" on Windows
If you encounter a "WARNING: The script clipcount.exe is installed in 'path' which is not on PATH.
" when running the above command on Windows, please refer to the following article.
Reference: 【Python Windows】pip install でPATHが通らない時の解決方法 | ゆすノート
If you see "WARNING: Failed to write executable - trying to use .deleteme logic
," please run the terminal with administrator privileges and then proceed with the installation. For more details, refer to the following article:
Reference: Error installing package with executable · Issue #9023 · pypa/pip
Quick Usage
Option | Description |
---|
clipcount -h | Display the help screen. |
clipcount --help_jp | Display the help screen in Japanese. |
clipcount -b | Output the character count after removing line breaks (\n or \r\n ). |
clipcount -s | Output the character count after removing half-width spaces. |
clipcount -S | Output the character count after removing full-width spaces. |
clipcount -t | Output the character count after removing tab characters (\t ). |
clipcount --split | Output the character count after removing all whitespace characters (line breaks, half-width spaces, full-width spaces, tabs). |
clipcount -m | Calculate characters with half-width alphanumeric characters as 0.5 and output the character count. |
Use it as a command-line tool to output character counts on the terminal:
clipcount [options]
It can also be imported into Python files:
from clipcount import clipcount
x = clipcount({options})
Example
Note: The examples below are executed in a "Windows" environment, so line breaks are counted as "\r\n
".
Copy the following text and run clipcount:
Read
clipboard text.
CLI
# Output the character count including whitespace characters
$ clipcount
21
- Remove half-width spaces and output:
# One half-width space is removed and output
$ clipcount -s
20
- Remove full-width spaces:
# The above spaces are half-width spaces, so nothing changes.
$ clipcount -S
21
# Line breaks are removed and output
$ clipcount -b
19
- Remove all whitespace characters:
# Full-width space characters are removed
$ clipcount -sSbt
18
Alternatively, using --split
yields the same result.
# Full-width space characters are removed
$ clipcount --split
18
- Calculate half-width alphanumeric characters as 0.5 and output:
# Half-width alphanumeric characters are counted as 0.5
$ clipcount -m
10.5
Import
It can also be used in a Python file with "import".
As a note, when passing commands to options, please exclude "-
" or "--
".
# Store the character count of the clipboard in a variable
from clipcount import clipcount
x = clipcount({"split"})
print(x)
# Produces the same result as "clipcount --split"
$ python foo.py
18
Usage
clipcount is a Python package that "reads the clipboard and outputs the character count."
By default, it outputs the "character count including whitespace characters (line breaks, half-width spaces, full-width spaces, tabs)."
It also calculates both half-width and full-width characters as "the same 1 character."
With various options, you can output the character count after removing each whitespace character.
When used in the terminal, options can be combined. For example, to output "the character count after removing only full-width spaces and tabs," you can use "clipcount -St
".
If you want to remove all whitespace characters at once, the "--split
" option can be used. This has the same meaning as "-bsSt
".
If you want to calculate half-width and full-width characters separately, you can use the "-m
" option. This is an option to calculate half-width characters as "0.5 characters." It may be useful when considering character counts in situations like WordPress titles or meta keywords.
Dependencies