[英]Convert a list returned by a map() function (from the Pool class) to a Dictionary in Python
[英]Dictionary returned empty when called from other function in python
我正在嘗試從其他功能訪問字典(兩個功能都在同一類中)。 但這給我空字典。
class c1():
def __init__(self):
self.test = {}
def func1(self,**dict1):
pprint(dict1) ## dict1 to this functions is passed from other python file and I am able to print this dict1 within in this function without any problem ##
return dict1
def func2(self):
self.test = self.func1() # After adding changes suggested still returning empty dict
您在func1()
中缺少return語句。
同樣,即使沒有打開字典,您也將調用不帶參數的func1()。
您可以嘗試以下方法:
def func2(self):
self.test = self.func1(name='Pablo')
我也相信在您的__init__()
, test
應該是self.test
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.