-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenerators.py
More file actions
122 lines (92 loc) · 2.84 KB
/
generators.py
File metadata and controls
122 lines (92 loc) · 2.84 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# yield saves memory
# it is used for lazy evaluation
# it remembers the state of the function
# def studyaboutYield():
# yield 'hi haider'
# yield 34
# gen = studyaboutYield()
# print(next(gen)) # hi haider
# print(next(gen)) # 34
# # print(next(gen)) # StopIteration error
# for value in studyaboutYield():
# print(value)
# def my_generator():
# received = yield "Ready"
# print("Received:", received)
# yield "Done"
# ali = my_generator()
# print(next(ali))
# print(next(ali))
# # print(next(ali))
# #
# def make_generator_infiite (): # this one is infinite loop that continoue , whenever we run the program
# anyvalue = 0
# while True:
# print("this value" , anyvalue)
# yield anyvalue
# anyvalue += 1
# ok = make_generator_infiite()
# next(ok)
# next(ok)
# next(ok)
# next(ok)
# # next(ok)
# # next(ok)
# # sending value into generator
# def hiHiader():
# print('any thing ')
# anyValue = yield
# while True:
# print(f"haider {anyValue}")
# anyValue = yield # if we do not use yield then it will continously running
# name = hiHiader()
# next(name)
# name.send('love')
# # yield from and close
# def anyFuckion():
# yield 'funck 1'
# yield 'funck 1'
# def anySecondFucnk ():
# yield 'funck 2'
# yield 'funck 2'
# def yield_from_function ():
# yield from anyFuckion() # foem is use here to get value from any other thing
# yield from anySecondFucnk()
# check = yield_from_function()
# next(check)
# print(next(check)) # ak ak kr k bi hm check kr sakty hn
# print(next(check))
# print(next(check))
# print(next(check))
# print(check.close())
# check.close()
# for eachone in yield_from_function(): # this one is the best approch or like a one line code
# print(eachone)
# def closeFunction ():
# try:
# while True:
# order = yield 'value yield TRY'
# except:
# print('value is yielded in EXCEPT')
# dooon = closeFunction()
# next(dooon)
# # dooon.close()
# what we learn yield , close , yield from , send , next
def hamra_decorator(Yahan_Pe_AK_Function_as_A_parameter_ata_HA): # ya to ho giya simple
def wapper_function_Ha():
print('function jo aya tha vo phaly')
Yahan_Pe_AK_Function_as_A_parameter_ata_HA()
print("function chalny k bad")
return wapper_function_Ha
@hamra_decorator
def koi_bi_Function_jo_hmnyPassKrnahoga():
print('function body')
koi_bi_Function_jo_hmnyPassKrnahoga()
def hamra_decorator_function_parameters_lanyVala(funk):
def wapperFunction(*args_Means_jotny_marzi_parameters_Ayn , **for_key_values):
return funk(*args_Means_jotny_marzi_parameters_Ayn , **for_key_values)
return wapperFunction
@hamra_decorator_function_parameters_lanyVala
def function_Puls (a,b):
return a+b
print(function_Puls(3,7))