第一个问题是,我通过web爬行提取csv数据,如下所示。在将csv数据的“设备”列应用到prop.value之后,我希望为每一行创建JSON文件,因此我希望通过for语句创建几个json文件。
第二个问题是,当打印prop.value时,只打印最后一行"CNC 5면가공기“。有结构性问题吗?
我正在使用AASPypi4.0项目的代码。
name Equipment Size Brand
HI_TRAX1950 CNC 수평 보링 머시닝 센터 6,000Wx1,250Lx3,500H KIHEUNG
MIMAX_W5050 CNC 5면 가공기 10,300Wx4,000Lx6000H KIHEUNG
Unit50 CNC 5면 가공기 10,000W × 5,000L × 3,500H SNK
for name, equipment in zip(data['name'], data['Equipment']):
prop= model.Property(
id_short='Specifications',
value_type=model.datatypes.String,
value = equipment,
semantic_id=model.Reference(
(model.Key(
type_=model.KeyElements.CONCEPT_DESCRIPTION,
local= True,
value='0173-1#02-BAA120#008',
id_type=model.KeyType.IRDI),)
))
submodel = Submodel(
kind= 'instance',
id_short= 'Technical_Data',
identification=model.Identifier('localhost:8080/TechnicalData',
model.IdentifierType.CUSTOM),
submodel_element={prop},
)
obj_store: model.DictObjectStore[model.Identifiable] = model.DictObjectStore()
obj_store.add(asset)
obj_store.add(submodel)
for comment in obj_store:
filename = f'/KL_TECH/Code_{comment}.json'
with open(filename 'w', encoding='utf-8') as json_file:
aas.adapter.json.write_aas_json_file(json_file, obj_store, indent = 4, ensure_ascii= False)发布于 2022-08-20 09:34:26
原因是因为当您使用with open(filename 'w', encoding='utf-8') as json_file:时,方法是w,这意味着它删除了之前的所有内容,然后写入新的值,所以应该将其更改为a
with open(filename 'w', encoding='utf-8') as json_file:
aas.adapter.json.write_aas_json_file(json_file, obj_store, indent = 4, ensure_ascii= False)至
with open(filename 'a', encoding='utf-8') as json_file:
aas.adapter.json.write_aas_json_file(json_file, obj_store, indent = 4, ensure_ascii= False)https://stackoverflow.com/questions/73425397
复制相似问题