![](/img/trans.png)
[英]How to display the word count with respect to word length (serially, i.e in an orderly fashion) using Python3?
[英]How to print particular id(i.e word ) from the result
嗨,我有以下代碼:
Z = [ [<Entity:0*7fasdas55c:type1101(1101,NGRID)id:-2600>, <Entity:0*5fafaef45c:type1101(1101,NGRID)id:-3665>]
, [<Entity:0*7fasdas55c:type1101(1101,NGRID)id:-5600>, <Entity:0*5fafaef45c:type1101(1101,NGRID)id:-545465>] ]
edge1= ansa.basecollectentity(constant.nastran, Z[0],'NODE')
print(edge1)
我的結果是
[<Entity:0*7fasdas55c:type1101(1101,NGRID)id:-2600>, <Entity:0*5fafaef45c:type1101(1101,NGRID)id:-3665>]
Enen 雖然代碼是用 ansa python 編寫的,但我的問題是 General
我想編寫一個代碼,使其通過“edge1”並在具有兩個不同名稱的 id 之后打印數字:例如
節點 1 = 2600
節點 2 = 3665
請幫助我編寫代碼,提前致謝
每個類使用__repr__()
特殊方法控制自己的可打印表示。
您正在查看的數字id:
可能位於實體中的任何位置、任何字段中或內部數據結構中的某個位置,或者在顯示時計算出的任何位置。 正如@PM2Ring 的評論所暗示的那樣,它可能很容易成為id
屬性 - 但它可能不是。
所以這要么是一個非常具體的問題 - 您需要檢查實體以獲取適當的字段或方法來獲取 ID。 而且你還沒有說它是什么,所以它可能是任何東西。
或者這是關於處理repr()
值的一般問題 - 這可能不是您想要做的,真的。
但如果你確實想要,那就是:
for count, item in enumerate(edge1):
id = repr(item).split(':')[-1].rstrip('>')
print "Node" + str(count), id
在 ansa 中說你有一個實體,例如:
nod=<Entity:0*7fasdas55c:type1101(1101,NGRID)id:-2600>
要打印 id,您可以使用:
Print(nod._id)
結果:
2600
您還可以使用._type
來獲取您正在處理的實體類型
希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.