简体   繁体   English

如何将class类型转换为字符串python SDK

[英]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它显示了这个outputclass 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.

相关问题 在 Python 中将 String 转换为 Object - Convert String to Object in Python 努力将字符串转换为 python 中的字典 - Struggling to convert string to Dict in python 无法将类型“[String: Any]”的返回表达式转换为返回类型“Song?” - Cannot convert return expression of type '[String : Any]' to return type 'Song?' Python Firestore 将 DateTime 转换为时间戳字符串 - Python Firestore convert DateTime to timestamp string 如何通过 python sdk 下载内容(视频)? - How to delivery content (video) by download with python sdk? 如何将 Athena 时间戳转换为字符串 - How to convert Athena timestamp to string 使用python使用boto3创建新服务器后如何捕获类型为class的instance_id - how to catch instance_id that is of type class after creating a new server with boto3 with python 无法转换类型为 java.lang.String 的 object [Android] - Can't convert object of type java.lang.String [Android] Golang:将自定义类型(别名 [32]byte)转换为字符串 - Golang: convert custom type (alias to [32]byte) to string golang:如何将类型接口 {} 转换为数组 - golang : how to convert type interface {} to array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM