import sys
try:
raise Exception('foobar')
except:
info = sys.exc_info()
print(type(e[2])) # <class 'traceback'>
help(traceback) # NameError: name 'traceback' is not defined
Python用于异常报告的回溯对象的类型究竟是什么?
sys.exc_info上的文档提到了参考手册,但是虽然我发现了很多关于如何操作回溯实例的信息,但我希望能够访问类型(类)本身。
答案 0 :(得分:6)
$Duration = Measure-Command {
$b = @()
foreach ($Property in $data.Property | Select -Unique) {
$Props = [ordered]@{ Property = $Property }
foreach ($Server in $data.Server | Select -Unique){
$Value = ($data.where({ $_.Server -eq $Server -and
$_.Property -eq $Property })).Value
$Props += @{ $Server = $Value }
}
$b += New-Object -TypeName PSObject -Property $Props
}
}
Write-Host "Finished transposing " -ForegroundColor Green -NoNewline
Write-Host "$(($data | Get-Member -MemberType Properties).count)/$($data.Count)" -ForegroundColor Yellow -NoNewline
Write-Host " columns/rows into " -ForegroundColor Green -NoNewline
Write-Host "$(($b | Get-Member -MemberType Properties).count)/$($b.Count)" -ForegroundColor Yellow -NoNewline
Write-Host " columns/rows in " -ForegroundColor Green -NoNewline
Write-Host $Duration.Milliseconds -ForegroundColor Yellow -NoNewline
Write-Host " Milliseconds" -ForegroundColor Green
$b | FT -AutoSize
$b | Out-GridView
$b | Export-Csv .\newData.csv -NoTypeInformation
object是类型模块下的TracebackType
实例。
traceback
types.TracebackType
对象的类型,例如traceback
中找到的对象。
sys.exc_info()[2]
作为pointed out by @user2357112,名称>>> from types import TracebackType
>>> isinstance(info[2], TracebackType)
True
>>> TracebackType
<class 'traceback'>
基本上是内部TracebackType
类型的别名,在类型模块中是set by raising an exception。实际的traceback
type可以在CPython代码中找到。