Python:为什么退货声明不起作用?

时间:2019-06-13 16:36:09

标签: python

我有一个非常奇怪的问题,退货不起作用。 我的代码:

def data_for_dump(action = None , type_of_dump = None, where_is_price = None, check = 'false', currentQty=None, unrealisedRoePcnt=None, last_price=None):
    if type_of_dump == 'control_panels':
        data = {
            'Action':{
                'Action':action,
                'Where_is_price':where_is_price,
            }
        }

        #return data
    elif type_of_dump == 'get_position_info':
        data = {
            'Info':{
                'check':check,
                'currentQty':currentQty,
                'unrealisedRoePcnt':unrealisedRoePcnt,
                'last_price':last_price,
            }
        }
    return data

当我这样调用此函数时

data_for__dump = data_for_dump(action = 'set_location',type_of_dump = 'control_panels', where_is_price = price_location)

它返回我:

<function data_for_dump at 0x7f409cdd7510>

这到底是什么?

2 个答案:

答案 0 :(得分:1)

以下在我的计算机上可以正常工作。

您的函数名称为data_for_dump,但这就是您正在调用的函数返回的变量。然后,当您尝试实际调用该函数以返回值时,即在调用data_for__dump,那么额外的_字符就很重要。

它以字符串形式返回函数。只需更正_即可调用该函数并切换变量名即可解决您的问题。

def data_for_dump(action = None , type_of_dump = None, where_is_price = None, check = 'false', currentQty=None, unrealisedRoePcnt=None, last_price=None):
    if type_of_dump == 'control_panels':
        data = {
            'Action':{
                'Action':action,
                'Where_is_price':where_is_price
                }
            }

        #return data
    elif type_of_dump == 'get_position_info':
        data = {
            'Info':{
                'check':check,
                'currentQty':currentQty,
                'unrealisedRoePcnt':unrealisedRoePcnt,
                'last_price':last_price
            }
        }

    return data

def main():
    data = data_for_dump(action = 'set_location',type_of_dump = 'control_panels', where_is_price = 3)
    print(data)
# Yields {'Action': {'Action': 'set_location', 'Where_is_price': 3}}

main()

答案 1 :(得分:0)

如果正在显示data_for_dump,则是预期的。我认为您应该改为打印data_for__dump。