[英]How to convert class type to string python SDK
我有这段code
可以打印与VM
相关的信息。 output
属于class type
。 我怎样才能convert
它转换成我能理解的形式?
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient
credential = ServicePrincipalCredentials(client_id='XXXX',
secret='XXXX', tenant='XXXX')
compute_client = ComputeManagementClient(
credential, 'XXXX')
for vm in compute_client.virtual_machines.list_all():
print(vm.storage_profile)
我在表格中收到output
。 它显示了这个output
的class
type
<'azure.mgmt.compute.v2019_03_01.models.storage_profile_py3.StorageProfile'>
它正在打印class
类型,因为您直接调用variable
而不转换它。 为此,您可以创建一个新变量并将转换分配给它并打印该新变量。 或者您可以直接在打印语句中使用,如下所示,
这也是@baileythegreen的建议,感谢您在回答中发布相同的宝贵见解以帮助其他社区成员。
代码:
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.compute import ComputeManagementClient
credential = ServicePrincipalCredentials(client_id='XXXX',
secret='XXXX', tenant='XXXX')
compute_client = ComputeManagementClient(
credential, 'XXXX')
for vm in compute_client.virtual_machines.list_all():
print(vm.storage_profile.as_dict())
有关更多信息,请参阅以下链接:-
SO 线程: Azure Python SDK - 列出虚拟机并生成自定义 JSON 响应
MS Q&A:- 打印虚拟机列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.