![]() |
| ||
| calling a function without changing scope Hi, My problem is that I have a large function with hundreds of lines. I want to break it apart into smaller functions. The issue is that if I make a module level function, the scope changes and I have to pass the necessary variables to it. This can be difficult if there are 10 variables that need to be passed. So basically I want to be able to call a function inside another function but keep the scope the same. I found a way to do something like this by defining a function inside another function: def main(): The thing with this is that it doesn't really shorten my larger function. So is it possible to get the effect of the above code with insideFunc defined somewhere that is not inside of main? |
| ||
| Re: calling a function without changing scope You can use a class to do that in the following way. You could also use a list or dictionary as a container for the 10 variables and pass one list/dictionary instead of 10 variables. IMHO using the class method is preferred. class test_class: |
| All times are GMT -4. The time now is 10:36 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC