我想将从文本文件中提取的数据读入Abaqus文件中进行模拟。 这是我的代码:
import os
os.chdir(r"dir")
for file in os.listdir("dir"):
if file.endswith('.txt'):
print os.path.join(r"dir", file)
with open(file) as f:
lines = f.readlines()
for line in lines[:-1]:
first, second = tuple(map(float, line.split()))
print '(%g, %g),' % (first, second),
first, second = tuple(map(float, lines[-1].split()))
pp = '(%g, %g)' % (first, second)
print pp
mdb.models['Model-1'].TabularAmplitude(data=(pp), name='NewAmplitude', smooth=
SOLVER_DEFAULT, timeSpan=STEP)
出现的错误是:
“TypeError:data; found string,expecting tuple”
任何人都可以帮忙解决问题吗?
答案 0 :(得分:0)
此代码应解决此问题:
import os
os.chdir(r"dir")
pp = []
for file in os.listdir("dir"):
if file.endswith('.txt'):
print os.path.join(r"dir", file)
with open(file) as f:
for line in f:
pp.append(map(float, line.split()))
print pp.__repr__()[1:-1]
mdb.models['Model-1'].TabularAmplitude(data=pp,
name='NewAmplitude',
smooth=SOLVER_DEFAULT,
timeSpan=STEP)