Two different values for same variable “args”

本小妞迷上赌 提交于 2019-12-01 05:37:32

问题


I am invoking a method from python script which has one of the variable as args. Once I step into the method, when I am trying to see the value of the the variable args, "print args" and just executing 'args' display two different values. Can anyone please let me know whats the difference between these two commands.

I expected both the commands to display same value.

(Pdb) print args
<lib.framework.testmanager.RunArgs object at 0xb26acac>

(Pdb) args
args = <lib.framework.testmanager.RunArgs object at 0xb26acac>
u = <upgradelib.UpgradeManager object at 0x946cf8c>
spec = {'excludeHosts': None, 'evacuateAllData': True, 'WaitTime': None, 'IssueType': 'Host Disconnect', 'performObjectUpgrade': True, 'downgradeFormat': False}
result = True

回答1:


args is a PDB debugger command. Use !args to show the actual variable.

See the Debugger Commands section:

a(rgs)
Print the argument list of the current function.

and

[!]statement
Execute the (one-line) statement in the context of the current stack frame. The exclamation point can be omitted unless the first word of the statement resembles a debugger command.

(Emphasis mine).

In your args output you can see the args argument value on the first line.

Personally, I find the (a)rgs command a little pointless; it prints all values using str() instead of repr(); this makes the difference between objects with similar __str__ output values invisible (such as str vs. unicode, or a BeautifulSoup Element vs. a string with HTML, etc.).



来源:https://stackoverflow.com/questions/29342420/two-different-values-for-same-variable-args

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!