Bangla Date and Numeral Utilities
Bangla is a Python package designed for converting Gregorian dates to the Bengali calendar, translating English numerals to Bangla numerals, and generating Bangla ordinals for dates. The current version is 0.0.5, and the library has an infrequent release cadence, with the last update in March 2021.
Common errors
-
ModuleNotFoundError: No module named 'bangla'
cause The `bangla` package is not installed in the current Python environment.fixInstall the package using pip: `pip install bangla` -
AttributeError: module 'bangla' has no attribute 'some_function_name'
cause Attempting to call a non-existent function or a function with an incorrect name from the `bangla` module, or using a class instance without calling its methods.fixReview the official documentation or source code for correct function and class names (e.g., `GregorianToBangla`, `eng_to_bangla_numeral`, `BanglaOrdinal`). Ensure you're calling methods on instantiated objects where appropriate (e.g., `date_converter.get_date()`). -
TypeError: 'str' object cannot be interpreted as an integer
cause Providing string inputs to date conversion methods (`GregorianToBangla`) that expect integer arguments for year, month, or day.fixEnsure that year, month, and day arguments for `GregorianToBangla` are integers, not strings. For example, use `GregorianToBangla(2023, 10, 26)` instead of `GregorianToBangla('2023', '10', '26')`.
Warnings
- gotcha The `bangla` library has not been updated since March 2021 (v0.0.5). While it may still function, it might not receive updates for new Python versions, bug fixes, or security patches, potentially leading to compatibility issues in the future.
- gotcha Input validation is minimal. Providing invalid dates (e.g., February 30th) or non-numeric input to functions like `GregorianToBangla` or `eng_to_bangla_numeral` might lead to incorrect conversions or unexpected runtime errors, rather than explicit, user-friendly exceptions.
Install
-
pip install bangla
Imports
- GregorianToBangla
from bangla import GregorianToBangla
- eng_to_bangla_numeral
from bangla import eng_to_bangla_numeral
- BanglaOrdinal
from bangla import BanglaOrdinal
Quickstart
from bangla import GregorianToBangla, eng_to_bangla_numeral, BanglaOrdinal
# Convert Gregorian date to Bangla
date_converter = GregorianToBangla(2023, 10, 26)
bangla_date = date_converter.get_date()
print(f"Gregorian 2023-10-26 in Bangla: {bangla_date}")
# Expected output: Gregorian 2023-10-26 in Bangla: কার্তিক ১০, ১৪৩০
# Translate English numerals to Bangla numerals
english_numeral = "2024"
bangla_numeral = eng_to_bangla_numeral(english_numeral)
print(f"English '{english_numeral}' in Bangla numeral: {bangla_numeral}")
# Expected output: English '2024' in Bangla numeral: ২০২৪
# Generate Bangla ordinal for a date
ordinal_generator = BanglaOrdinal(2023, 10, 26)
bangla_ordinal = ordinal_generator.get_ordinal()
print(f"Bangla ordinal for 26th: {bangla_ordinal}")
# Expected output: Bangla ordinal for 26th: ২৬শে