0

I am doing my project on incremental deep drawing using ABAQUS.
I am trying to import a text file of loop program into abaqus script so that there is no need of entering amplitude values manually.

But I am getting an error when trying to import the data using the following code

f = open('data_x', 'r')
values=f.read()
values=f.readline()

Error:

data_x is not defined

Timothy
  • 2,004
  • 3
  • 23
  • 29

1 Answers1

1

Error NameError: name 'data_x' is not defined points that you are using data_x as a name in your code, not as a string (with quotes).

This means that in your code, you probably have something like

f = open(data_x)

Python is trying to figure out which value is associated with data_x, which is a Python name, not a string. Since it's not defined before getting to that line, you are getting an error.

If you want to store the name of a file and then open a file, write

data_x = 'data_x.txt'
f = open(data_x)

You could also directly write

f = open('data_x.txt')

Whichever solution you adopt, make sure that a correct path to the file is passed to the function open, so that it could find the file.

hgazibara
  • 1,832
  • 1
  • 19
  • 22
  • thanks for the solution but now its giving an error TypeError: data; found string, expecting tuple can you help me with this – Manohar Reddy Jul 20 '16 at 09:51
  • You might want to open a new question, unless it's really connected tightly to this one. – hgazibara Jul 20 '16 at 10:03
  • the exact code is f = open('data_x.txt', 'r') values=f.read() values=f.readline() when calling data_x at some other point its showing above stated error like TypeError: data; found string, expecting tuple – Manohar Reddy Jul 20 '16 at 10:07
  • You should show us the code at which the error is happening and some context around it to figure out the solution. – hgazibara Jul 20 '16 at 10:51