This Python script translates text to Morse code and vice versa. It also supports replacing periods and dashes with Morse code equivalents.
The Morse code dictionary used in the script is as follows:
morse_code = {
'A': '·—',
'B': '—·',
# ... (other letters, numbers, and characters)
' ': ' / ',
'0': '—————',
'1': '·————',
# ... (other numbers)
'.': '·—·—·—',
',': '——··——',
'?': '··——··',
'!': '—·—·——',
'"': '·—··—·'
}
- Translate text to Morse code.
- Translate Morse code to text.
- Handle spaces, numbers, and common punctuation.
pip install morse-py3
To use the script, run the following command:
morse-py3 [options]
input_string
: The input for the translator.--morse
: Translate input to Morse code.--text
: Translate input from Morse code to text.
# Translate text to Morse code
morse-py3 "Hello World" --morse
# Translate Morse code to text
morse-py3 ".... . .-.. .-.. --- / .-- --- .-. .-.. -.. " --text
The script gracefully handles unrecognized characters and provides informative error messages.
argparse
This Morse code translator script is licensed under the MIT License.
Feel free to use and modify this script for your Morse code translation needs! Contributions and feedback are welcome. If you encounter any issues or have suggestions for improvement, please open an issue on the GitHub repository.