python中,创建一个包含machineIp、componentPath、dumpName、dumpSize、dumpTime这几个字段的对象
时间: 2023-07-04 08:22:43 浏览: 92
在Python中,可以使用字典(dict)来创建一个包含 `machineIp`、`componentPath`、`dumpName`、`dumpSize`、`dumpTime` 这几个字段的对象。示例代码如下:
```python
# 创建包含machineIp、componentPath、dumpName、dumpSize、dumpTime这几个字段的对象
obj = {
"machineIp": "192.168.0.1",
"componentPath": "/usr/local/bin",
"dumpName": "core_dump",
"dumpSize": 1024,
"dumpTime": "2022-08-01 12:00:00"
}
# 输出该对象
print(obj)
```
输出结果为:
```python
{'machineIp': '192.168.0.1', 'componentPath': '/usr/local/bin', 'dumpName': 'core_dump', 'dumpSize': 1024, 'dumpTime': '2022-08-01 12:00:00'}
```
如果需要创建多个这样的对象,可以将它们放在一个列表(list)中,示例代码如下:
```python
# 创建多个包含machineIp、componentPath、dumpName、dumpSize、dumpTime这几个字段的对象
objs = [
{
"machineIp": "192.168.0.1",
"componentPath": "/usr/local/bin",
"dumpName": "core_dump",
"dumpSize": 1024,
"dumpTime": "2022-08-01 12:00:00"
},
{
"machineIp": "192.168.0.2",
"componentPath": "/usr/local/lib",
"dumpName": "heap_dump",
"dumpSize": 2048,
"dumpTime": "2022-08-02 12:00:00"
}
]
# 输出这些对象
print(objs)
```
输出结果为:
```python
[
{
'machineIp': '192.168.0.1',
'componentPath': '/usr/local/bin',
'dumpName': 'core_dump',
'dumpSize': 1024,
'dumpTime': '2022-08-01 12:00:00'
},
{
'machineIp': '192.168.0.2',
'componentPath': '/usr/local/lib',
'dumpName': 'heap_dump',
'dumpSize': 2048,
'dumpTime': '2022-08-02 12:00:00'
}
]
```
阅读全文