'p'在Django中有特殊含义吗?

Pet*_*sen 2 python django

为什么p和p8在以下代码中有所不同?

视图函数的开头(在名为"proteinSearch"的Django应用程序中的文件views.py中,名为"Protein"的模型具有名为"description"的字段):

def searchForProteins2(request, searchStr):
    p8 = Protein.objects.filter( description__icontains=searchStr)

    #Why doesn't this work?????
    p  = Protein.objects.filter( description__icontains=searchStr)

    import pdb; pdb.set_trace()
Run Code Online (Sandbox Code Playgroud)

在pdb中交互式:

    (Pdb) searchStr
    u'centr'
    (Pdb) p8
    [<Protein: IPI00657962.1>, <Protein: IPI00479143.2>, <Protein: IPI00477050.4>, <Protein: IPI00220625.1>,
    95.2>]
    (Pdb) p
    *** SyntaxError: SyntaxError('unexpected EOF while parsing', ('<string>', 0, 0, ''))
Run Code Online (Sandbox Code Playgroud)

sim*_*rsh 13

当您处于调试模式(pdb或ipdb REPL)时,'p'表示特定功能,即评估表达式expr.

喜欢,

ipdb> x = 1
ipdb> p x
1
ipdb> p x==True
True
ipdb> p x==1
True
Run Code Online (Sandbox Code Playgroud)

在Django中,'p'只是一个变量.

如果要打印'p'变量的值,请尝试,

ipdb> p p
Run Code Online (Sandbox Code Playgroud)

:)