0

Hi,

I have a question ask you or expert. Can python's function return a class at the end of function definition. The class have only a set of data members like struct in C. Please help and thanks in advance. Any good reference on this topic?

John

3
Contributors
4
Replies
7
Views
9 Years
Discussion Span
Last Post by jliu66
0

Code something up and try it for yourself. If you get an error message then post the code here for some help.

0

Here is the code:

def ols(x, y):

class output:
    pass

results = output()

results.method = 'ols'
results.y = y
results.nobs = n
results.nvar = nvar
results.beta = B

return results

It looks like the above is not working with exit code 0 after exeuction. What normally python return exit code after execution? I tested one with exit code 0. I am not sure it is normal or not.

Another thing is there any good debug tool in IDE showing the values in variables during debug? The one IDE coming with Python Win does not have this function. Maybe I am wrong.

Edited by pritaeas: Fixed markdown

0

This code runs fine:

def ols(x, y):

    class output:
        pass

    results = output()

    results.method = 'ols'
    results.y = y
    #results.nobs = n
    #results.nvar = nvar
    #results.beta = B

    return results

r = ols(1,2)
print r

I think the problem with yours might have been that you were accessing non-existent variables n, nvar, and B.

Jeff

0

This code runs fine:

def ols(x, y):

    class output:
        pass

    results = output()

    results.method = 'ols'
    results.y = y
    #results.nobs = n
    #results.nvar = nvar
    #results.beta = B

    return results

r = ols(1,2)
print r

I think the problem with yours might have been that you were accessing non-existent variables n, nvar, and B.

Jeff

Thanks so much, Jeff.

John

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.