mirror of
https://github.com/TriM-Organization/Musicreater.git
synced 2026-04-24 02:05:57 +00:00
完美,同志,完美!!!!!!!
This commit is contained in:
21
resources/test/genexpr_vs_yieldfrom.py
Normal file
21
resources/test/genexpr_vs_yieldfrom.py
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
# 模拟两种写法
|
||||
def method_A(self, start, end):
|
||||
yield from (f"{track}.get_range(start, end)" for track in self)
|
||||
|
||||
def method_B(self, start, end):
|
||||
return (f"{track}.get_range(start, end)" for track in self)
|
||||
|
||||
|
||||
|
||||
tracks = ["A", "B"]
|
||||
|
||||
gen_a = method_A(tracks, 0, 10)
|
||||
print(list(gen_a))
|
||||
|
||||
|
||||
|
||||
gen_b = method_B(tracks, 0, 10)
|
||||
print(list(gen_b))
|
||||
|
||||
# they are the same output
|
||||
Reference in New Issue
Block a user