Method returns blank even though it isn't blank inside method
Question: I have written a small scrip (this is partial), the full code should search a
bunch of .c files and check if the parameters within it are being used or not.
This particular code is responsible for grabbing the parameter from a row, so
it can be used to search the .c files for identical parameter names and it's
values.

The issue is that the first instant of print (inside `takeTheParam` method)
shows the correct parameter in command prompt, while the second print instant
(after the call to the `takeTheParam` method) shows a blank in command prompt.

    
    
    import os
    
    theParam = ""
    
    def takeTheParam(row, theParam):
        for item in row.split():
            if "_" in item:
                theParam = item
                print theParam
                return theParam
    
    
    for root, dirs, files in os.walk('C:/pathtoworkdir'):
        for cFile in files:
            if cFile.endswith('.c'):
                with open(os.path.join(root, cFile), 'r') as this:
                    for row in this:
                        if '=' in row:
                            takeTheParam(row, theParam)
                            print theParam
                            while theParam not in usedParameters:  # Has the param already been checked?
                                value(row, savedValue, statements, cur)
                                searchAndValueExtract(theParam, parameterCounter, compareValue)
                                while isEqual(savedValue, compareValue, equalValueCounter):
                                    searchAndValueExtract(theParam, parameterCounter, compareValue)
                                else:
                                    # If IsEqual returns false, that means a param has different values 
                                    # and it's therefore being used
                                    usedParameters.append(theParam)
                                    pass
    

I have't got enough experience in python to figure out why this happens, but I
suspect that when `theParam` is used outside of the method it's value it
retrieved from it's definition on the beginning of the code (`theParam = ""`)
and I have no idea why, if this is the case.


Answer: Change

    
    
     takeTheParam(row, theParam)
    

to

    
    
    theParam = takeTheParam(row, theParam)
    

The returned variable is never assigned to `theParam` in your case, so it
would stay `""` forever. Now it isn't anymore.

