There are three py-files in one folder:
main.py module.py submodule.py Contents of the submodule.py file:
import random def func(): x = random.randint(1, 100) return x Contents of the module.py file:
from submodule import func data = [ ('number', func()), ('param', 'key'), ] The contents of the main.py file
from module import data while True: response = requests.post(url='http://site.com', data=data) When you run the main.py file, the output is as follows:
[('number', 8), ('param', 'key')] [('number', 8), ('param', 'key')] [('number', 8), ('param', 'key')] [('number', 8), ('param', 'key')] [('number', 8), ('param', 'key')] [('number', 8), ('param', 'key')] [('number', 8), ('param', 'key')] [('number', 8), ('param', 'key')] Dear experts. How can I get the func() function to execute each time the while loop passes without transferring the function to another module?
datafunction, not an object ... if you want it to be an object, then you can make it mimic the list (maybe there is something ready) ... other options are possible, depending on what requests the requests.post () to parameters ... - Fat-Zerdata = [func()]withget_data = lambda: [func()]and then in a loop:data=get_data()) - jfs