0

I got the following problem: I'm writing a script for Ensight (a program for visualizing CFD computations) in python. The program Ensight gives me a list for the time values like:

print ensight.query(ensight.TIMEVALS)['timevalues']
[[0, 0.0], [1, 9.99e-07], [2, 1.99e-06], [3, 0.0003],etc.]

Where the first value in every list is the timestep and the second value the actual time at this timestep. Now I want to ask somehow for timestep '2' and want to know the corresponding second value of the list. Therefore if I could just find the index of the timestep I could easily have the corresponding time value.

EDIT\\ It solved it now like this:

time_values = ensight.query(ensight.TIMEVALS)['timevalues']
for start,sublist in enumerate(time_values):
    if step_start in sublist:
        index_begin = start
for end,sublist in enumerate(time_values):
    if step_stop in sublist:
        index_end = end

3 Answers 3

1

Maybe this is what you want?

print ensight.query(ensight.TIMEVALS)['timevalues'][1][1]

That should print the 9.99e-07 as it is the second value in the second list included in your main list.

I'm just wondering why you have 3 opening and just 2 closing brackets. Is this a typo?

[[ [..].. ]

If you have a list like myList = [[0, 0.0], [1, 9.99e-07], [2, 1.99e-06], [3, 0.0003],etc.] you can access the first nested list with myList[0] resulting in [0, 0.0] To access the second value in that list you can use myList[0][1]

Sign up to request clarification or add additional context in comments.

1 Comment

yes sorry, that was a typo! That is not what I want, because I'm generating a GUI where one can enter from which time step to which time step one wants to evaluate certain variables. And I want to prevent errors in case of the loaded CFD case file doesn't start with timestep = 0
1

Set n to the required timestep value

>>> n=2
>>> print [list[1] for list in ensight.query(ensight.TIMEVALS)['timevalues'] if list[0]=n ]

this can also be extended in your case

>>> from=2
>>> to=100
>>> print [list[1] for list in ensight.query(ensight.TIMEVALS)['timevalues'] if (list[0]>from && list[0]<to)  ]

Comments

1
>>> l = ensight.query(ensight.TIMEVALS)['timevalues']

>>> print l
[[0, 0.0], [1, 9.99e-07], [2, 1.99e-06], [3, 0.0003]]

>>> _d = {int(ele[0]): ele[1] for ele in l}

>>> print _d[2]
1.99e-o6

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.