Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple python-abaqus question

Status
Not open for further replies.

Cansand

Structural
Jan 14, 2007
102
I am learning Python... while going through a simple example in the Doc
I have copied the statements below into a file called distance.py in my local directory C.
Then (as instructed in the ABAQUS Doc) I typied the following at the system prompt:

abaqus python distance.py 30 40

but the ABAQUS\6.5.1\cae\python.exe: can't open file'distance'

can anybody tell me why. in addition what are '30 40' for in the statement abaqus python distance.py 30 40


import sys, math
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def distance(x, y):
"""
Prints distance from origin to (x, y).

Takes two command line arguments, x and y.
"""

# Square the arguments and add them.

a = x**2 + y**2

# Return the square root.

return math.sqrt(a)

# Retrieve the command line arguments and
# convert the strings to floating-point numbers.

x = float(sys.argv[1])
y = float(sys.argv[2])

# Call the distance function.

d = distance(x, y)

# Print the result.

print 'Distance to origin = ', d
 
Replies continue below

Recommended for you

1. You should run the command in the same directory as you saved the "distance.py" file.

2. If you look at the commands in your script:
x = float(sys.argv[1])
y = float(sys.argv[2])
you'll understand what the "30 40" mean. They are "arguments". Python processes arguments just like other programming languages (C, C++, perl etc etc)

Finally, you should check out a good genreal python programming guide such as Practical Python. You'll get a lot of good background understanding such as this...
 
helppoorpeople,
I am just curious, do you find this forum helpful in anyway ?
 
I hope so... he's been getting a lot of help lately!
 
xerf and breg
Thank you for your replies
It is definitely helpful forum regardless of coming across some curious and arrogant replies sometimes.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor