【问题标题】:returned dictionary value is 'None' python返回的字典值为“无”python
【发布时间】:2011-03-28 16:08:45
【问题描述】:

我在一个文件中有一个函数,我在一个单独的脚本中调用它(如下所示)。直接从函数打印可以正常工作,但是当我尝试将值返回到脚本时,它会发送“无”。

任何帮助将不胜感激。 谢谢

脚本:

import modules.functions as f

restype = 'THR'
atomtype = 'CA'

print f.AtomType(restype,atomtype)

函数:(这是函数中返回值的部分)

def AtomType(resName,atomType):
    def threonine():
        print 'well im here'
        atoms = {'N' : 1,
                 'CA': 6,
                 'C' : 8,
                 'O' : 2,
                 'CB': 6,
                 'OG1': 1,
                 'CG2': 4, 
                 }    

            print atoms[atomType]
            return atoms[atomType]

    residues = {'ALA' : hydrophobic,
                'ARG' : arginine,
                'ASN' : asparagine,
                'ASP' : aspartate,
                'CYS' : cysteine,
                'GLN' : glutamine,
                'GLU' : glutamate,
                'GLY' : hydrophobic,
                'HIS' : histidine,
                'ILE' : hydrophobic,
                'LEU' : hydrophobic,
                'LYS' : lysine,
                'MET' : methionine,
                'PHE' : phenylalanine,
                'PRO' : proline,
                'SER' : serine,
                'THR' : threonine,
                'TRP' : tryptophan,
                'TYR' : tyrosine,
                'VAL' : hydrophobic,
                }

    residues[resName]()

我得到的输出是:

well im here
6
None

编辑:添加整个功能

【问题讨论】:

  • 第一个代码sn-p没有调用第二个代码sn-p中的函数。第二个sn -p中的函数不接受任何参数,但无论如何访问了一些神秘的atomType。这有点令人困惑......也许你可以发布你真的试图运行的代码?
  • 你能给我们看一段完整的代码来重现故障吗?
  • 你打电话给f.AtomType并发布了threonine()的代码。请张贴f.AtomType()的代码

标签: python dictionary return-value


【解决方案1】:

这是一个猜测:AtomType 调用 threonine,但没有返回它的返回值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 2015-01-01
    • 2021-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多