passing a variable (data) to a function/class
Posted: Sun May 21, 2017 8:58 pm
Hi.
It might be a silly question, but when I thought, that my Python skills are good enough I encountered a problem.
I started validating my skills writing a program. It got bigger and bigger so I decided to split it in a few files. I use threading so I'm passing some args to the functions which are in separate files now. Initially I had problems with making variables global, but eventually I could make some of them global. I do need global variables to change their values from different parts of program (those separate files/modules). The exact structure that makes me troubles is like this:
I need the variable path in another_func that is called from the MyClass (which in turn is called from main code of module2, but the variable path originally comes from the main code of the main file. How to do it? I tried a few things, but the only thing (that I think should work and seems easy to do) I haven't tried yet is to modify the class (which isn't mine) to take another argument. What do you think about it? How do you pass over 'data' between modules/parts of a program?
Thanks!
It might be a silly question, but when I thought, that my Python skills are good enough I encountered a problem.
I started validating my skills writing a program. It got bigger and bigger so I decided to split it in a few files. I use threading so I'm passing some args to the functions which are in separate files now. Initially I had problems with making variables global, but eventually I could make some of them global. I do need global variables to change their values from different parts of program (those separate files/modules). The exact structure that makes me troubles is like this:
Code: Select all
#main file with variable <path> which I want to pass over to module2 (separate file with <thread_func> function)
another_thread = threading.Thread(target=module2.func, args=(path))
timelapse_thread.start()
#module2 file that is structured as below
def func():
def another_func():
'''some code'''
class MyClass():
def do_something():
'''some code'''
another_func()
'''some code'''
something_that_uses_the_class(MyClass)
#some code
returnThanks!