How to get the original variable name of variable passed to a function
        Posted  
        
            by Acorn
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Acorn
        
        
        
        Published on 2010-05-01T11:57:18Z
        Indexed on 
            2010/05/01
            12:07 UTC
        
        
        Read the original article
        Hit count: 378
        
Is it possible to get the original variable name of a variable passed to a function? E.g.
foobar = "foo"
def func(var):
    print var.origname
So that:
func(foobar)
Returns:
>>foobar
EDIT:
All I was trying to do was make a function like:
def log(soup):
    f = open(varname+'.html', 'w')
    print >>f, soup.prettify()
    f.close()
.. and have the function generate the filename from the name of the variable passed to it.
I suppose if it's not possible I'll just have to pass the variable and the variable's name as a string each time.
© Stack Overflow or respective owner