[英]How to convert class type to string python SDK
I have this code
that prints information related to VM
.我有这段code
可以打印与VM
相关的信息。 The output
is in the class type
. output
属于class type
。 How can I convert
it to a form so that I can understand it?我怎样才能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)
I am getting output
in the form.我在表格中收到output
。 It is showing the class
type
of this output
它显示了这个output
的class
type
<'azure.mgmt.compute.v2019_03_01.models.storage_profile_py3.StorageProfile'> <'azure.mgmt.compute.v2019_03_01.models.storage_profile_py3.StorageProfile'>
It was printing class
type because you are directly calling the variable
without converting it.它正在打印class
类型,因为您直接调用variable
而不转换它。 To do that You can create a new variable and assign the conversion to it and print that new variable.为此,您可以创建一个新变量并将转换分配给它并打印该新变量。 Or you can use directly in print statement as below,或者您可以直接在打印语句中使用,如下所示,
Which is suggested by @ baileythegreen as well,Thank you for your valuable insights posting the same in answer to help other community members.这也是@baileythegreen的建议,感谢您在回答中发布相同的宝贵见解以帮助其他社区成员。
CODE:代码:
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())
For more information please refer the below links:-有关更多信息,请参阅以下链接:-
SO THREAD: Azure Python SDK - list VMs and generate custom JSON response SO 线程: Azure Python SDK - 列出虚拟机并生成自定义 JSON 响应
MS Q&A:- Printing list of Virtual Machines MS Q&A:- 打印虚拟机列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.