mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 19:50:30 +01:00
py: Allow keyword arguments for namedtuple
This commit is contained in:
@@ -6,19 +6,19 @@ except ImportError:
|
||||
T = namedtuple("Tup", ["foo", "bar"])
|
||||
# CPython prints fully qualified name, what we don't bother to do so far
|
||||
#print(T)
|
||||
t = T(1, 2)
|
||||
print(t)
|
||||
print(t[0], t[1])
|
||||
print(t.foo, t.bar)
|
||||
for t in T(1, 2), T(bar=1, foo=2):
|
||||
print(t)
|
||||
print(t[0], t[1])
|
||||
print(t.foo, t.bar)
|
||||
|
||||
print(len(t))
|
||||
print(bool(t))
|
||||
print(t + t)
|
||||
print(t * 3)
|
||||
print(len(t))
|
||||
print(bool(t))
|
||||
print(t + t)
|
||||
print(t * 3)
|
||||
|
||||
print([f for f in t])
|
||||
print([f for f in t])
|
||||
|
||||
print(isinstance(t, tuple))
|
||||
print(isinstance(t, tuple))
|
||||
|
||||
try:
|
||||
t[0] = 200
|
||||
@@ -39,6 +39,16 @@ try:
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
try:
|
||||
t = T(foo=1)
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
try:
|
||||
t = T(1, foo=1)
|
||||
except TypeError:
|
||||
print("TypeError")
|
||||
|
||||
# Try single string
|
||||
# Not implemented so far
|
||||
#T3 = namedtuple("TupComma", "foo bar")
|
||||
|
||||
Reference in New Issue
Block a user