Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

python - Extracting integer from a tuple list containing a mix of characters and integers

I would like to extract an integer(30) from a tuple list as shown below which comes after the set "vertices". The code has to have some logic to look for after vertices.

(mdb.models['model-3'].rootAssembly.instances['Circular_knit - 2, 3, 3-1'].vertices[30], (-3.61088101472848e-14, 5.0, -3.95139073393513e-16))

I found examples to extract this integer when the tuple is comprising only in integers. My case here is that it is after a specific set of character("vertices") that I want to extarct the integer value('30'). I would appreciate any advise on this.

>>>v
[mdb.models['model-3'].rootAssembly.instances['Circular_knit - 2, 3, 3-1'].vertices[30], (-3.61088101472848e-14, 5.0, -3.95139073393513e-16)]
>>> v[0]
mdb.models['model-3'].rootAssembly.instances['Circular_knit - 2, 3, 3-1'].vertices[30]
k=v[0]
k=str(k)
>>> i=0
>>> num_list = [int(i.split('[')[1]) for i in k]
IndexError: list index out of range
question from:https://stackoverflow.com/questions/66051460/extracting-integer-from-a-tuple-list-containing-a-mix-of-characters-and-integers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Always look at the documentation first: it can actually save you a lot of time!

Lets split your object mdb.models['model-3'].rootAssembly.instances['Circular_knit - 2, 3, 3-1'].vertices[30]:

  • mdb - high-level Abaqus model database object. Among other members it has a container models which contain all models of your the actual database;
  • .models['model-3'] - Model object with the name 'model-3'. Among it's members you can find rootAssembly.
  • .rootAssembly - a root object for all your instances (approximately as model object is a "root" for all your parts);
  • .instances['Circular_knit - 2, 3, 3-1'] - an Instance object which is an instance of one of your Part objects. It contains many members and one among them is vertices container (Note that if you are working with an orphan mesh you will have only nodes, but no vertices).
  • .vertices[30] - finally here you are accessing the vertex under the index '30', so as a result, you have the Vertex object. Any vertex object has several members and one of them is index.

So, the answer to your question will be:

v[0].index

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...