mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
python: iter_method
This commit is contained in:
15
rootfs_overlay/lkmc/python/iter_method.py
Executable file
15
rootfs_overlay/lkmc/python/iter_method.py
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# https://cirosantilli.com/linux-kernel-module-cheat#python
|
||||
|
||||
class MyClass():
|
||||
def __init__(self, mylist):
|
||||
self.mylist = mylist
|
||||
def __iter__(self):
|
||||
return iter(self.mylist)
|
||||
|
||||
mylist = [1, 3, 2]
|
||||
i = 0
|
||||
for item in MyClass(mylist):
|
||||
assert item == mylist[i]
|
||||
i += 1
|
||||
Reference in New Issue
Block a user