如何使用新元素打印列表

时间:2019-04-22 05:56:21

标签: python

我正在尝试通过烧瓶打印html页面上的关键字列表,该烧瓶在doc文件中新近更新。但是在打印时它会追加到现有列表中。我尝试每次清除时都需要新文件,但没有用。我该如何解决

    $sqrs_prop = $sqrs.properties

    $rule_name_list = $sqrs_prop.DisplayName
    foreach($rule_name in $rule_name_list){
        Write-Host "disabling $rule_name"
        if($rule_name -ne $null){

        $ruleUri = "https://management.azure.com/subscriptions/$cur_sub/resourcegroups/$resourceGroupName/providers/microsoft.insights/scheduledQueryRules/$rule_name"+"?api-version=2018-04-16"
         $bodyEnable = "
         {
             'properties': {
               'enabled': 'false'
             }
           }
         "
         Write-Verbose "ResourceURI being invoked: $ruleUri"

        try {
            $disablerule = Invoke-RestMethod -Method PATCH -Uri $ruleUri -Headers $headers -Body $bodyEnable
            $disablerule | Select-Object @{Name="displayName";Expression={$_.properties.displayName}}, @{Name="IsEnabled";Expression={$_.properties.enabled}},@{Name="lastUpdate";Expression={$_.properties.lastUpdatedTime}}, @{Name="provisioningState";Expression={$_.properties.provisioningState}} | Format-Table -AutoSize -Wrap
            Write-Verbose "Output of Invoke-RestMethod: $disablerule"
             }
          catch
             {
                Write-Error "$_"
             }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

将重置插入到循环中,例如:

for sentence in sentences:
    ref_list.clear()
    ref_data_list.clear()

代替

ref_list.clear()
ref_data_list.clear()
for sentence in sentences: