簡體   English   中英

python返回None

[英]python return None

我試圖以字典的形式從函數返回對象。 似乎在函數內部工作正常,但返回“ None”。

================================================== =打印結果為::

{'tree1': [<ROOT.TH1D object ("root2_tree_tree1_px_hist") at 0x7fa40eec05b0>, <ROOT.TH1D object ("root2_tree_tree1_py_hist") at 0x7fa40eec0cd0>, <ROOT.TH1D object ("root2_tree_tree1_pz_hist") at 0x7fa40eec13f0>], 'tree2': [<ROOT.TH1D object ("root2_tree_tree2_px_hist") at 0x7fa40eec2620>, <ROOT.TH1D object ("root2_tree_tree2_py_hist") at 0x7fa40eec2f20>, <ROOT.TH1D object ("root2_tree_tree2_pz_hist") at 0x7fa40eeb4850>]}

{'tree1': [None, None, None], 'tree2': [None, None, None]}

所以,現在我很困惑。 它在功能上打印正確的值,但未正確返回。 代碼如下。

def set_histograms():
    .
    .
    .
    print(DichistList)  # this would correctly print dictionary 
    return DichistList

def main():
    DICHISTLIST = set_histograms()
    print(DICHISTLIST)  # this is printing "None", why?

因此,這可能與您使用ROOT的事實有關,除非您使用特定的軟件包,否則ROOT和python的效果不佳。 我強烈建議您檢查root_numpy,我在粒子物理學時曾廣泛使用它。

示例:讀取包含ttree mytree的myfile.root:

from root_numpy import root2array
myarray = root2array( 'myfile.root', 'mytree' ) )

您可以使用以下命令立即將其轉換為熊貓數據框:

df = pd.DataFrame( myarray )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM