Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb1d3ef1

Browse files
author
zacharyaanglin
committed
Added dataclass example to MenuConfig
1 parentd1be3e1 commitb1d3ef1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

‎README.md‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,41 @@ class MenuConfig(NamedTuple):
303303

304304
defcreate_menu(config: MenuConfig):
305305
title, body, button_text, cancellable= config
306+
# ...
307+
308+
309+
create_menu(
310+
MenuConfig(
311+
title="My delicious menu",
312+
body="A description of the various items on the menu",
313+
button_text="Order now!"
314+
)
315+
)
316+
```
317+
318+
**Even fancier**
319+
```python
320+
from dataclassesimport astuple, dataclass
321+
322+
323+
@dataclass
324+
classMenuConfig:
325+
"""A configuration for the Menu.
326+
327+
Attributes:
328+
title: The title of the Menu.
329+
body: The body of the Menu.
330+
button_text: The text for the button label.
331+
cancellable: Can it be cancelled?
332+
"""
333+
title:str
334+
body:str
335+
button_text:str
336+
cancellable:bool=False
337+
338+
defcreate_menu(config: MenuConfig):
339+
title, body, button_text, cancellable= astuple(config)
340+
# ...
306341

307342

308343
create_menu(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp