By: Matheus C. Fernandes, Nick Vasios, Ben Gorissen and Katia Bertoldi

Date Updated: 2/21/2019

Intro

In this document we will go over the basics of Python programming necesseray to construct an ABAQUS python script. In order to effectively write ABAQUS scripts it is important to realize how Python itself works and how Python is implemented in ABAQUS. For this tutorial I am using what is called an Jupyter notebook to run Python commands. Jupyter notebooks are not supported in ABAQUS - so this is used only for this tutorial and nothing else related to ABAQUS.

Python Versions

Python is a widely used programming language outside of ABAQUS. You may have heard of it's name here or there since it is an open source free software package anyone can download and install in their computers. A lot of the web and applications use Python as a language. ABAQUS many years ago, adopted Pythons as it's main scirpting language for all of it's software. It is important to note that as any open source language, Python has been evolving to different versions over time. As these versions evolve, free open source packages as well as the base syntax of Python has also evolved. The most current version of Python adopted by industry is version 3.6. ABAQUS scripting uses it's own proprietary installation of Python, and that installation up until ABAQUS 2018 version is still stuck at Python 2.7. To check the version of Python you're using you can simply type the following two lines on the Python prompt:

import sys
sys.version

The output for ABAQUS 2017 yields the response

'2.7.3 (default, Feb  6 2016, 06:24:46) [MSC v.1700 64 bit (AMD64)]'

Which is far from the standard Python versions used in installations of Anaconda etc.

Now that we have covered some basic background, we will go over some useful commands that you can use in ABAQUS. We will focus on the syntax used for Python version 2.7 instead of Python 3.6 because that is what is used in ABAQUS.

Variable Types and Operations

As any other programing language, when you define a variable, the variable takes shape as different types. Variable types can vary from strings, to integers and dictionaries. Here we will go over some nuances in defining variable types and changing variable types.

Let's begin by defining 3 different variables in slightly different ways and checking what type of variable it is.

In [152]:
# this is a comment and will not run as a command!
a=3
b=3.5
c='t'
print type(a)
print type(b)
print type(c)
<type 'int'>
<type 'float'>
<type 'str'>

Now what happens if we do simple multiplication and addition operations.

In [12]:
print a*a
print a*b
9
10.5

Now what happens if we do power operations. Note: you may be used from Matlab syntax that to make something to the power of something you use ^ but in Python the syntax is to use ** instead.

In [17]:
print a**b
46.7653718044

The carrot symbol ^ is used for bitwise XOR operation. Each bit position in the result is the logical XOR of the bits in the corresponding position of the operands. (1 if the bits in the operands are different, 0 if they are the same.) This is not particularly useful for ABAQUS scripting, but certainly something that could cause a numerical bug when making computations assuming it is providing the power operation. Note: for this operation I am only performing the operation on integers and not on floats (doing this operation of floats would give you an error).

In [27]:
print 1^1
print 1^2
print 1^3
0
3
2

Now, to the most common bug you will bang your head against the wall figuring out what is going on. Accidentally doing an operation with an integer instead of a float. If you cannot figure out why you have a bug in your code, you should start thinking: where did I accidentally define an integer instead of a float.

In [15]:
print a
print 1/a
3
0

An easy way to fix this is to simply always use a . at the end of each variable operation and definition when you want it to be a float.

In [28]:
print 1./a
0.333333333333

You can also do multiplication operations on strings as seen below.

In [18]:
print c*a
ttt

You can only do operations on strings using integers. So, if I convert the integer into a float it will spit an error

In [153]:
print c*float(a)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-153-e2623d87dcb4> in <module>()
----> 1 print c*float(a)

TypeError: can't multiply sequence by non-int of type 'float'

You can also do incrementations to your variables very quickly. The two following expressions are equivalent.

In [154]:
x=1.
y=3.
x=x+1.
y+=5.

print 'x =',x,'; y =',y
x = 2.0 ; y = 8.0
In [158]:
y+=5
print y
28.0

You can find more information on oerators in Python, in this following page: https://realpython.com/python-operators-expressions/

Printing Different File Types

The reason this is useful is because this is also how you would print your output obtained from the ODB into a text file. We will cover printing into a text file at a later section in this document.

In [35]:
string1 = 'World'
print 'Hello', string1

string2 = '!'
print 'Hello', string1, string2
Hello World
Hello World !
In [36]:
print 'Hello' + string1 + string2
HelloWorld!
In [37]:
print "Hello %s" % string1
Hello World

Similarly, when using other data types

  • %s -> string
  • %d -> Integer
  • %f -> Float
  • %o -> Octal
  • %x -> Hexadecimal
  • %e -> exponential
In [159]:
print "Actual Number = %d" %18
print "Float of the number = %f" %18
print "Octal equivalent of the number = %o" %18
print "Hexadecimal equivalent of the number = %x" %18
print "Exponential equivalent of the number = %e %f" % (18,17)
Actual Number = 18
Float of the number = 18.000000
Octal equivalent of the number = 22
Hexadecimal equivalent of the number = 12
Exponential equivalent of the number = 1.800000e+01 17.000000

To add a now line to your string you use the \n or \r for Mac file type editors. Python itself will interpret either. To be safe, I recommend using both \n\r.|

In [160]:
print "Jan\nFeb\nMar\nApr\nMay\n\nJun\n\rJul\rAug"
Jan
Feb
Mar
Apr
May

Jun
Aug

PrecisionWidth and FieldWidth

Fieldwidth is the width of the entire number and precision is the width towards the right. One can alter these widths based on the requirements.

The default Precision Width is set to 6.

In [41]:
"%f" % 3.121312312312
Out[41]:
'3.121312'

Notice upto 6 decimal points are returned. To specify the number of decimal points, '%(fieldwidth).(precisionwidth)f' is used.

In [42]:
"%.5f" % 3.121312312312
Out[42]:
'3.12131'

If the field width is set more than the necessary than the data right aligns itself to adjust to the specified values.

In [43]:
"%9.5f" % 3.121312312312
Out[43]:
'  3.12131'

Zero padding is done by adding a 0 at the start of fieldwidth.

In [44]:
"%020.5f" % 3.121312312312
Out[44]:
'00000000000003.12131'

For proper alignment, a space can be left blank in the field width so that when a negative number is used, proper alignment is maintained.

In [45]:
print "% 9f" % 3.121312312312
print "% 9f" % -3.121312312312
 3.121312
-3.121312

'+' sign can be returned at the beginning of a positive number by adding a + sign at the beginning of the field width.

In [48]:
"%-9.3f" % 3.121312312312
Out[48]:
'3.121    '

Data Structures

In simple terms, It is the the collection or group of data in a particular structure.

Lists

Lists are the most commonly used data structure. Think of it as a sequence of data that is enclosed in square brackets and data are separated by a comma. Each of these data can be accessed by calling it's index value.

Lists are declared by just equating a variable to '[ ]' or list.

In [49]:
a = []
print type(a)
<type 'list'>
In [161]:
x = ['apple', 'orange']

Indexing

In python, Indexing starts from 0. Thus now the list x, which has two elements will have apple at 0 index and orange at 1 index.

In [162]:
x[1]
Out[162]:
'orange'

Indexing can also be done in reverse order. That is the last element can be accessed first. Here, indexing starts from -1. Thus index value -1 will be orange and index -2 will be apple.

In [165]:
x[-2]
Out[165]:
'apple'
In [53]:
y = ['carrot','potato']

Here we have declared two lists x and y each containing its own data. Now, these two lists can again be put into another list say z which will have it's data as two lists. This list inside a list is called as nested lists and is how an array would be declared which we will see later.

In [56]:
z  = [x,y]
print z
[['apple', 'orange'], ['carrot', 'potato']]

Indexing in nested lists can be quite confusing if you do not understand how indexing works in python. So let us break it down and then arrive at a conclusion.

Let us access the data 'apple' in the above nested list. First, at index 0 there is a list ['apple','orange'] and at index 1 there is another list ['carrot','potato']. Hence z[0] should give us the first list which contains 'apple'.

In [57]:
z1 = z[0]
print z1
['apple', 'orange']

Now observe that z1 is not at all a nested list thus to access 'apple', z1 should be indexed at 0.

In [58]:
z1[0]
Out[58]:
'apple'

Instead of doing the above, In python, you can access 'apple' by just writing the index values each time side by side.

In [59]:
z[0][0]
Out[59]:
'apple'

If there was a list inside a list inside a list then you can access the innermost value by executing z[ ][ ][ ].

Slicing

Indexing was only limited to accessing a single element, Slicing on the other hand is accessing a sequence of data inside the list. In other words "slicing" the list.

Slicing is done by defining the index values of the first element and the last element from the parent list that is required in the sliced list. It is written as parentlist[ a : b ] where a,b are the index values from the parent list. If a or b is not defined then the index value is considered to be the first value for a if a is not defined and the last value for b when b is not defined.

In [166]:
num = [0,1,2,3,4,5,6,7,8,9]
In [167]:
print num[0:4]
print num[4:]
print num[:2]
[0, 1, 2, 3]
[4, 5, 6, 7, 8, 9]
[0, 1]

You can also slice a parent list with a fixed length or step length.

In [112]:
num[:9:3]
Out[112]:
[0, 3, 6]

Built in List Functions

To find the length of the list or the number of elements in a list, len( ) is used.

In [113]:
len(num)
Out[113]:
10

If the list consists of all integer elements then min( ) and max( ) gives the minimum and maximum value in the list.

In [65]:
min(num)
Out[65]:
0
In [66]:
max(num)
Out[66]:
9
In [172]:
range(len(num))
Out[172]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Lists can be concatenated by adding, '+' them. The resultant list will contain all the elements of the lists that were added. The resultant list will not be a nested list.

In [1]:
[1,2,3] + [5,4,7]
Out[1]:
[1, 2, 3, 5, 4, 7]

There might arise a requirement where you might need to check if a particular element is there in a predefined list. Consider the below list.

In [2]:
names = ['Earth','Air','Fire','Water']

To check if 'Fire' and 'Rajath' is present in the list names. A conventional approach would be to use a for loop and iterate over the list and use the if condition. But in python you can use 'a in b' concept which would return 'True' if a is present in b and 'False' if not.

In [3]:
'Fire' in names
Out[3]:
True
In [4]:
'Matt' in names
Out[4]:
False

append( ) is used to add a element at the end of the list.

In [5]:
lst = [1,1,4,8,7]
In [6]:
lst.append(1)
print lst
[1, 1, 4, 8, 7, 1]

count( ) is used to count the number of a particular element that is present in the list.

In [7]:
lst.count(1)
Out[7]:
3

append( ) function can also be used to add a entire list at the end. Observe that the resultant list becomes a nested list.

In [173]:
lst1 = [5,4,2,8]
In [177]:
lst.append(lst1)
print lst
[1, 1, 4, 8, 7, 1, [5, 4, 2, 8], [5, 4, 2, 8], [5, 4, 2, 8], [5, 4, 2, 8], [5, 4, 2, 8]]
In [185]:
lst[1]=[10,10.,'str']
print lst
[1, [10, 10.0, 'str'], 4, 8, 7, 1, [5, 4, 2, 8], [5, 4, 2, 8], [5, 4, 2, 8], [5, 4, 2, 8], [5, 4, 2, 8]]

Tuples

Tuples are similar to lists but only big difference is the elements inside a list can be changed but in tuple it cannot be changed. Think of tuples as something which has to be True for a particular something and cannot be True for no other values.

To define a tuple, A variable is assigned to paranthesis ( ) or tuple( ).

In [186]:
tup = ()
tup2 = tuple()
In [189]:
print type(tup)
print type(tup2)
<type 'tuple'>
<type 'tuple'>

If you want to directly declare a tuple it can be done by using a comma at the end of the data.

In [11]:
27,
Out[11]:
(27,)

27 when multiplied by 2 yields 54, But when multiplied with a tuple the data is repeated twice.

In [12]:
2*(27,)
Out[12]:
(27, 27)
In [192]:
type((27))
Out[192]:
int

Values can be assigned while declaring a tuple. It takes a list as input and converts it into a tuple or it takes a string and converts it into a tuple.

In [13]:
tup3 = tuple([1,2,3])
print tup3
(1, 2, 3)

It follows the same indexing and slicing as Lists.

In [14]:
print tup3[1]
2
In [200]:
tup4=(5,6,7,)
print tup4[1]
tup4=list(tup4)
tup4[1]=10
tup4=tuple(tup4)
print tup4
6
(5, 10, 7)

Mapping one tuple to another¶

In [15]:
(a,b,c)= ('alpha','beta','gamma')
In [16]:
print a,b,c
alpha beta gamma

Dictionaries

Dictionaries are more used like a database because here you can index a particular sequence with your user defined string.

To define a dictionary, equate a variable to { } or dict()

In [17]:
d0 = {}
d1 = dict()
print type(d0), type(d1)
<type 'dict'> <type 'dict'>

Dictionary works somewhat like a list but with an added capability of assigning it's own index style.

In [18]:
d0['One'] = 1
d0['OneTwo'] = 12 
print d0
{'OneTwo': 12, 'One': 1}

That is how a dictionary looks like. Now you are able to access '1' by the index value set at 'One'

In [203]:
print d0['One']
1

Two lists which are related can be merged to form a dictionary.

In [20]:
names = ['One', 'Two', 'Three', 'Four', 'Five']
numbers = [1, 2, 3, 4, 5]

zip( ) function is used to combine two lists

In [21]:
d2 = zip(names,numbers)
print d2
[('One', 1), ('Two', 2), ('Three', 3), ('Four', 4), ('Five', 5)]

The two lists are combined to form a single list and each elements are clubbed with their respective elements from the other list inside a tuple. Tuples because that is what is assigned and the value should not change.

Further, To convert the above into a dictionary. dict( ) function is used.

In [22]:
a1 = dict(d2)
print a1
{'Four': 4, 'Five': 5, 'Three': 3, 'Two': 2, 'One': 1}

The dictionary is divided into keys and values. Keys are the key names that calls a particular value. To know all the keys of a particular dictionary you can use the .key() command.

In [23]:
a1.keys()
Out[23]:
['Four', 'Five', 'Three', 'Two', 'One']

To obtain the values of a dictionary just use the .values() command.

In [25]:
a1.values()
Out[25]:
[4, 5, 3, 2, 1]

Control Flow Statements

if

In [206]:
x = 12 
y = 10
if x>10 or y<9:
    print "here"
here

If -else

In [208]:
x = 9
if x > 10:
    print "hello"
else:
    print "world"
world

if -elif

In [28]:
x = 10
y = 12
if x > y:
    print "x>y"
elif x < y:
    print "x<y"
else:
    print "x=y"
x<y

if statement inside a if statement or if-elif or if-else are called as nested if statements.

In [29]:
x = 10
y = 12
if x > y:
    print "x>y"
elif x < y:
    print "x<y"
    if x==10:
        print "x=10"
    else:
        print "invalid"
else:
    print "x=y"
x<y
x=10

Loops

for

In [217]:
listhere=range(6)
listhere[3]=10
print listhere
for i in range(len(listhere)):
    print listhere[i]
[0, 1, 2, 10, 4, 5]
0
1
2
10
4
5
In [225]:
for i in a1.keys():
    print i
#     print a1[i]
Four
Five
Three
Two
One

In the above example, i iterates over the 0,1,2,3,4. Every time it takes each value and executes the algorithm inside the loop. It is also possible to iterate over a nested list illustrated below.

In [228]:
list_of_lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9],8]
for list1 in list_of_lists:
        print list1
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
8
In [244]:
lol=list_of_lists*3
print lol
lol[2][1]=[1,[1,[1]]]
print lol
lol[2][1][1][1][0]
[[1, 2, 3], [4, 5, 6], [7, [1, [1, [1]]], 9], 8, [1, 2, 3], [4, 5, 6], [7, [1, [1, [1]]], 9], 8, [1, 2, 3], [4, 5, 6], [7, [1, [1, [1]]], 9], 8]
[[1, 2, 3], [4, 5, 6], [7, [1, [1, [1]]], 9], 8, [1, 2, 3], [4, 5, 6], [7, [1, [1, [1]]], 9], 8, [1, 2, 3], [4, 5, 6], [7, [1, [1, [1]]], 9], 8]
Out[244]:
1

A use case of a nested for loop in this case would be,

In [32]:
list_of_lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
for list1 in list_of_lists:
    for x in list1:
        print x
1
2
3
4
5
6
7
8
9
In [250]:
print [i**2-i*2 for i in [10,5,10] if 10<11]
[80, 15, 80]

Enumerate

In [116]:
for i,name in enumerate(['Matt','Ben','Nick','Katia']):
    print i,name
0 Matt
1 Ben
2 Nick
3 Katia

While

In [33]:
i = 1
while i < 3:
    print(i ** 2)
    i = i+1
print('Bye')
1
4
Bye

Break

As the name says. It is used to break out of a loop when a condition becomes true when executing the loop.

In [34]:
for i in range(100):
    print i
    if i>=7:
        break
0
1
2
3
4
5
6
7

Try-Except

Somtimes if something you know may or may not work you can add the following functionality

In [123]:
x=1
y=2
try:
   print x+y
except:
    pass
print 'continuing code'
3
continuing code
In [251]:
print 10
print x+zzz
print 9
10
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-251-279c2b03a0c1> in <module>()
      1 print 10
----> 2 print x+zzz
      3 print 9

NameError: name 'zzz' is not defined
In [254]:
try:
    print x+zzz
except:
    print 'oops, variable not defined'
    pass 
print 'continuing code'
oops, variable not defined
continuing code

Or you can do an assert and break the code not to wait too long assert <condition>,<error message>

In [258]:
x=10
assert x==10,'not 10'
print 'continuing code'
continuing code
In [125]:
assert x>20,'x not more than 20'
print 'continuing code'
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-125-6b487194eea7> in <module>()
----> 1 assert x>20,'x not more than 20'
      2 print 'continuing code'

AssertionError: x not more than 20

Function

Most of the times, In a algorithm the statements keep repeating and it will be a tedious job to execute the same statements again and again and will consume a lot of memory and is not efficient. Defining a function firstfunc().

In [265]:
def firstfunc():
    print "Hey!"
    print "How do you do?"
In [266]:
firstfunc()
Hey!
How do you do?

We can make the function take arguments and perform an operation on those argument.

In [272]:
def add(x,y):
    z=x+y
    return z
In [273]:
def mult(x,y):
    return x*y
In [274]:
print add(1.,2.)
3.0
In [275]:
print mult(3.,3.)
9.0
In [276]:
print add(1,3)/mult(3,3)
0
In [277]:
print add(1.,2.)/mult(1.,3.)
1.0

Classes

Variables, Lists, Dictionaries etc in python is a object. Without getting into the theory part of Object Oriented Programming, explanation of the concepts will be done along this tutorial.

In ABAQUS you don't need to know how to define classes, but it is important to know how to use them. Most, if not all of ABAQUS scripting is implemented as object oriented programing (aka classes). So ignore my definitions for classes in the following cell as this is what they are doing in the background.

In [279]:
class FirstClass:
    def __init__(self,name,symbol):
        self.name = name
        self.symbol = symbol
        self.value = symbol
    def square(self):
        self.value = self.value * self.value
    def cube(self):
        self.value =  self.symbol**3.
    def multiply(self, x):
        self.value = self.value * x
    def printVal(self):
        print self.value
    class Nest:            
        def Nest1(self):
            print "inseid 1"
        def Nest2(self):
            print "inside 2"

eg1 = FirstClass('one',1)
eg2 = FirstClass('two',2)

Now let's do some operations on the objects

In [280]:
print eg1.name
print eg2.name
one
two

We can figure out what types of operations you can do on a class.

In [281]:
dir(eg1)
Out[281]:
['Nest',
 '__doc__',
 '__init__',
 '__module__',
 'cube',
 'multiply',
 'name',
 'printVal',
 'square',
 'symbol',
 'value']
In [284]:
eg1.square()
eg2.square()
eg1.printVal()
eg2.printVal()
1
256

You can create shortcuts for a object as well

In [89]:
eg1.Nest().Nest1()
inseid 1
In [90]:
eg3=eg1.Nest()
eg3.Nest2()
inside 2
In [92]:
dir(eg3)
Out[92]:
['Nest1', 'Nest2', '__doc__', '__module__']

Importing Libraries

Because ABAQUS uses its own instalation of Python, you are limited to the libraries they have included in their installation. When you generate a journal file, you will notice all of the libraries that are imported in default for the ABAQUS objects we talked about in the last section of this document. One very useful library that is implemented in ABAQUS is NUMPY.

If you like MATLAB, NUMPY's syntax closely matches that of MATLAB. So, lets first begin looking at the different ways you can import a library such as NUMPY.

In [287]:
import numpy as np 
import scipy

Now, you can use np as a calling object for numpy

In [97]:
print np.linspace(1,10,100)
[  1.           1.09090909   1.18181818   1.27272727   1.36363636
   1.45454545   1.54545455   1.63636364   1.72727273   1.81818182
   1.90909091   2.           2.09090909   2.18181818   2.27272727
   2.36363636   2.45454545   2.54545455   2.63636364   2.72727273
   2.81818182   2.90909091   3.           3.09090909   3.18181818
   3.27272727   3.36363636   3.45454545   3.54545455   3.63636364
   3.72727273   3.81818182   3.90909091   4.           4.09090909
   4.18181818   4.27272727   4.36363636   4.45454545   4.54545455
   4.63636364   4.72727273   4.81818182   4.90909091   5.           5.09090909
   5.18181818   5.27272727   5.36363636   5.45454545   5.54545455
   5.63636364   5.72727273   5.81818182   5.90909091   6.           6.09090909
   6.18181818   6.27272727   6.36363636   6.45454545   6.54545455
   6.63636364   6.72727273   6.81818182   6.90909091   7.           7.09090909
   7.18181818   7.27272727   7.36363636   7.45454545   7.54545455
   7.63636364   7.72727273   7.81818182   7.90909091   8.           8.09090909
   8.18181818   8.27272727   8.36363636   8.45454545   8.54545455
   8.63636364   8.72727273   8.81818182   8.90909091   9.           9.09090909
   9.18181818   9.27272727   9.36363636   9.45454545   9.54545455
   9.63636364   9.72727273   9.81818182   9.90909091  10.        ]

Useful NUMPY commands and integration with lists

In [105]:
arr=[[0,1,2,3],[4,5,6,7]]
print arr
print type(arr)
[[0, 1, 2, 3], [4, 5, 6, 7]]
<type 'list'>
In [288]:
arrNP=np.array(arr,dtype='float')
In [289]:
print arrNP
print type(arrNP)
[[ 0.  1.  2.  3.]
 [ 4.  5.  6.  7.]]
<type 'numpy.ndarray'>
In [108]:
arr[0][1]
Out[108]:
1
In [292]:
list(arrNP[:1,1])
Out[292]:
[1.0]

Writing Text Files

In this section we will learn really quick how to write text files. This is important for when you want to extract values from an ABAQUS ODB and write it into a text file for post processing somewhere else.

In [307]:
fileID=open('file.txt','w')
In [308]:
type(fileID)
Out[308]:
file
In [309]:
llist1=[1.,2.,4.,5.,6.]
llist2=[1.,1.,1.,1.,1.]
In [310]:
for i in range(len(llist1)):
    fileID.write('%e, %e\r\n' % (llist1[i],llist2[i],))
for i in range(len(llist1)):
    print '{},matt,{}'.format(llist1[i],llist2[i])
1.0,matt,1.0
2.0,matt,1.0
4.0,matt,1.0
5.0,matt,1.0
6.0,matt,1.0

Always make sure to close the file you opened

In [311]:
fileID.close()

Reading Text Files

As many things in python, there are multiple ways of doing the same thing. Here I will show an inefficient way of reading text file inputs and a more efficient way of doing the same thing. First, the less efficient, but potentially more useful:

In [315]:
fileID=open('file.txt', 'r')
x=fileID.read()
fileID.close()
In [323]:
x=x.split(',')
print x
['1.000000e+00', ' 1.000000e+00\r\n2.000000e+00', ' 1.000000e+00\r\n4.000000e+00', ' 1.000000e+00\r\n5.000000e+00', ' 1.000000e+00\r\n6.000000e+00', ' 1.000000e+00\r\n']
In [324]:
x[4]
Out[324]:
' 1.000000e+00\r\n6.000000e+00'

Now the more efficient and less usefull, but using numpy Read the following ref: https://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html

In [326]:
x=np.loadtxt('file.txt',delimiter=',')
print x
[[ 1.  1.]
 [ 2.  1.]
 [ 4.  1.]
 [ 5.  1.]
 [ 6.  1.]]
In [328]:
x[:,1]
Out[328]:
array([ 1.,  1.,  1.,  1.,  1.])
In [329]:
x2=[1,2,3]
In [330]:
print x2*2
[1, 2, 3, 1, 2, 3]
In [336]:
print x[:,1]*2
[ 2.  2.  2.  2.  2.]

Executing Python Files

Say you have a separate file with a libary of functions inside. Or you want to have a shortcut way of execting a python file from ABAQUS' command prompt. The following line of code is what you're looking for...

In [ ]:
execfile('MyPythonFile.py')
In [ ]: