# Switch
## Introduction
Switch is a Python library that provides a simple and flexible switch statement implementation. It allows you to write cleaner and more readable code by eliminating the need for long chains of if-else statements.
## Usage
The switch library provides a Switch class that can be used to create switch statements. The Switch class takes a value as an argument, which is the value to be compared against the cases.
The case method takes a condition as an argument. If the condition evaluates to True, the corresponding function is executed. The default method is executed if no match is found.
### Here is an example of how to use the Switch class:
```rb
from switch import Switch
with Switch(1) as s:
if s.case(s.value == 1):
pass
if s.case(s.value == 2):
pass
if s.case(s.value == 3):
print("1, 2, 3!!")
raise Break() # Exit the Switch context
if s.case(s.value == 4):
print("Won't see this... :(")
if s.default:
print('default')
```
## Features:
- Simple and intuitive syntax
- Flexible conditions
- Support for multiple cases
- Default case handling
- Exception handling for breaking out of the switch statement
## Benefits:
- Improved code readability
- Reduced code complexity
- Easier to maintain and debug
## Conclusion:
The switch library is a valuable tool for any Python developer who wants to write cleaner and more readable code. It is a simple and flexible way to implement switch statements in Python.
Raw data
{
"_id": null,
"home_page": "https://github.com/TheDataDave/switch",
"name": "simple-switch",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "python, conditional, logic, switch, case, if-else, if, else",
"author": "David Flanders",
"author_email": "thedatadave@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/21/f0/413939142b1a19a7e84524ec405694e030a124c9375260479ddf55fe8457/simple-switch-0.2.0.tar.gz",
"platform": null,
"description": "# Switch\r\n\r\n## Introduction\r\n\r\nSwitch is a Python library that provides a simple and flexible switch statement implementation. It allows you to write cleaner and more readable code by eliminating the need for long chains of if-else statements.\r\n\r\n## Usage\r\nThe switch library provides a Switch class that can be used to create switch statements. The Switch class takes a value as an argument, which is the value to be compared against the cases.\r\n\r\nThe case method takes a condition as an argument. If the condition evaluates to True, the corresponding function is executed. The default method is executed if no match is found.\r\n\r\n### Here is an example of how to use the Switch class:\r\n```rb\r\nfrom switch import Switch\r\n\r\nwith Switch(1) as s:\r\n if s.case(s.value == 1):\r\n pass\r\n if s.case(s.value == 2):\r\n pass\r\n if s.case(s.value == 3):\r\n print(\"1, 2, 3!!\")\r\n raise Break() # Exit the Switch context\r\n if s.case(s.value == 4):\r\n print(\"Won't see this... :(\")\r\n if s.default:\r\n print('default')\r\n```\r\n\r\n## Features:\r\n - Simple and intuitive syntax\r\n - Flexible conditions\r\n - Support for multiple cases\r\n - Default case handling\r\n - Exception handling for breaking out of the switch statement\r\n \r\n## Benefits:\r\n - Improved code readability\r\n - Reduced code complexity\r\n - Easier to maintain and debug\r\n \r\n## Conclusion:\r\nThe switch library is a valuable tool for any Python developer who wants to write cleaner and more readable code. It is a simple and flexible way to implement switch statements in Python.\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A simple and flexible switch statement implementation for Python.",
"version": "0.2.0",
"project_urls": {
"Homepage": "https://github.com/TheDataDave/switch"
},
"split_keywords": [
"python",
" conditional",
" logic",
" switch",
" case",
" if-else",
" if",
" else"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c026f80b9a6a64933aeb2d494d715624902edbf2c67448e5e099b67e4644dbc2",
"md5": "bd52dc61a08efe82096902a325c59b37",
"sha256": "ff32391151d2ad385f7a0b4929b8a60e4210722421ccfc624318dcce79ef99bc"
},
"downloads": -1,
"filename": "simple_switch-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bd52dc61a08efe82096902a325c59b37",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 3639,
"upload_time": "2024-05-16T08:34:09",
"upload_time_iso_8601": "2024-05-16T08:34:09.010036Z",
"url": "https://files.pythonhosted.org/packages/c0/26/f80b9a6a64933aeb2d494d715624902edbf2c67448e5e099b67e4644dbc2/simple_switch-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "21f0413939142b1a19a7e84524ec405694e030a124c9375260479ddf55fe8457",
"md5": "df17f596dd47d4e24717d31a599829a7",
"sha256": "6c8d05c570107b18da280dac566c9f391ed5531b4cd9ecf85254614e9bade198"
},
"downloads": -1,
"filename": "simple-switch-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "df17f596dd47d4e24717d31a599829a7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3292,
"upload_time": "2024-05-16T08:34:14",
"upload_time_iso_8601": "2024-05-16T08:34:14.402873Z",
"url": "https://files.pythonhosted.org/packages/21/f0/413939142b1a19a7e84524ec405694e030a124c9375260479ddf55fe8457/simple-switch-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-16 08:34:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "TheDataDave",
"github_project": "switch",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "simple-switch"
}