-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreservedOrderKwargs.py
More file actions
43 lines (31 loc) · 884 Bytes
/
PreservedOrderKwargs.py
File metadata and controls
43 lines (31 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon May 10 00:06:42 2021
@author: maherme
"""
#%%
# Since Python 3.6 the order in which keyword arguments are collected into
# **kwargs is now maintained.
from sys import version_info
print(version_info)
#%%
def func(**kwargs):
for item in kwargs.items():
print(item)
func(b=100, a=200, y='hello', p='python')
#%%
from collections import namedtuple
def defaulted_namedtuple(class_name, **fields):
Struct = namedtuple('Struct', fields.keys())
Struct.__new__.__defaults__ = tuple(fields.values())
return Struct
Vector2D = defaulted_namedtuple('Vector2D',
x1=None, y1=None,
x2=None, y2=None,
origin_x=0, origin_y=0)
print(Vector2D)
print(Vector2D._fields)
v1 = Vector2D(10, 10, 20, 20)
print(v1)
#%%