scripting with Python

This is the place for queries that don't fit in any of the other categories.

scripting with Python

Postby ferial » Sat Sep 07, 2013 12:54 am

Dear all, I am doing a simple scripting with Python for a Abaqus odb reading, so i want to extract the max value and its Node label of my list (reading via a loop)
Code: Select all
#
for v in centerDisplacement.values:
    print 'Node label          = ', v.nodeLabel
    print 'X displacement = ', v.data[0]
#

-----------------------------
Node label = 1
X displacement =0.000
Node label = 2
X displacement =1.050
Node label = 3
X displacement =2.306
--------------------------------
So, I want to print at next

Max displacement = 2.306
For the Node label= 3

Thanks
ferial
 
Posts: 2
Joined: Sat Sep 07, 2013 12:47 am

Re: scripting with Python

Postby micseydel » Sat Sep 07, 2013 6:08 am

What attempt have you made to read your end goal?
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 929
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: scripting with Python

Postby stranac » Sat Sep 07, 2013 8:18 am

You could either use max() with a key function or, since you're already looping, you can keep a running maximum.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 897
Joined: Thu Feb 07, 2013 3:42 pm

Re: scripting with Python

Postby ferial » Sat Sep 07, 2013 9:59 am

Please more explications i'm very new in Python syntaxes
Thank
ferial
 
Posts: 2
Joined: Sat Sep 07, 2013 12:47 am

Re: scripting with Python

Postby stranac » Sat Sep 07, 2013 10:07 am

Here's an explanation of key functions: https://wiki.python.org/moin/HowTo/Sort ... _Functions
The only difference is you would use max() instead of sorted().

What I mean by running maximum:
  • make the first element the maximum
  • for every element in the list:
    • if the displacement is bigger than current maximum, make it the new maximum
  • when you're done looping, you will know what the maximum element is
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 897
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: sagaboth and 3 guests