abaqus Python实例——操作excel文件
目前处理数据离不开excel,所以pythoner必须学会用python操作excel表格。Python与excel交互方法也比较多,我一开始就接触的xlrd/xlwt包。直到现在也没有发现什么bug或者缺点,而且上次从ujs505那里知道Win32Com的方法在64bit系统下无效了,但是xlrd/xlwt方法依然好用,我欣喜万分。
这里给出我一个从材料单轴拉伸数据TRA文件中处理得到拉伸过程中各种应力应变量并记录到excel中的例子,其实这个例子比较乱,但是实在没有时间给弄个明了的版本了。大家将就看看
from math import *
import sys
import re
import xlrd
from xlwt import Workbook
book=Workbook()
sheet=book.add_sheet('test_NT',cell_overwrite_ok=True)
这里给出我一个从材料单轴拉伸数据TRA文件中处理得到拉伸过程中各种应力应变量并记录到excel中的例子,其实这个例子比较乱,但是实在没有时间给弄个明了的版本了。大家将就看看
from math import *
import sys
import re
import xlrd
from xlwt import Workbook
book=Workbook()
sheet=book.add_sheet('test_NT',cell_overwrite_ok=True)
sheet1=book.add_sheet('engineer',cell_overwrite_ok=True)
sheet2=book.add_sheet('True',cell_overwrite_ok=True)
sheet3=book.add_sheet('Plastic',cell_overwrite_ok=True)
sheet4=book.add_sheet('Plastic_modify',cell_overwrite_ok=True)
total_nubmer=46
nclown=0
nclown_e=0
nclown_t=0
nclown_p=0
nclown_pm=0
for i in range(total_nubmer):
myfile='tensile-'+str(i+1)
f=open(myfile+'.TRA','r')
engineer_strain=[]
true_strain=[]
sheet2=book.add_sheet('True',cell_overwrite_ok=True)
sheet3=book.add_sheet('Plastic',cell_overwrite_ok=True)
sheet4=book.add_sheet('Plastic_modify',cell_overwrite_ok=True)
total_nubmer=46
nclown=0
nclown_e=0
nclown_t=0
nclown_p=0
nclown_pm=0
for i in range(total_nubmer):
myfile='tensile-'+str(i+1)
f=open(myfile+'.TRA','r')
engineer_strain=[]
true_strain=[]
engineer_stress=[]
true_stress=[]
plastic_strain=[]
test_force=[]
adline()
adline()
adline()
adline()
s1=re.sub('"|\t|;|\n',' ',s1)
s1=re.split(' +',s1)
true_stress=[]
plastic_strain=[]
test_force=[]
adline()
adline()
adline()
adline()
s1=re.sub('"|\t|;|\n',' ',s1)
s1=re.split(' +',s1)
name=s1[2]
little=name[-2:]
s2=re.sub('"|\t|;|\n',' ',s2)
s2=re.split(' +',s2)
times=s2[2]
little=name[-2:]
s2=re.sub('"|\t|;|\n',' ',s2)
s2=re.split(' +',s2)
times=s2[2]
print name+'run'+str(times)
bk=xlrd.open_workbook('Static report.xls')
sh=bk.sheet_by_name("Stat")
ll_value(i+2,4)
area=pi*((diameter)**2)/4
python怎么读取dat文件 E_ll_value(i+2,7)
state=True
adlines()
s0=s0[-2]
s0=re.sub(';',' ',s0)
s0=re.split(' +',s0)
f.seek(0)
adline()
adline()
adline()
bk=xlrd.open_workbook('Static report.xls')
sh=bk.sheet_by_name("Stat")
ll_value(i+2,4)
area=pi*((diameter)**2)/4
python怎么读取dat文件 E_ll_value(i+2,7)
state=True
adlines()
s0=s0[-2]
s0=re.sub(';',' ',s0)
s0=re.split(' +',s0)
f.seek(0)
adline()
adline()
adline()
adline()
while state:
adline()
s=re.sub(';',' ',s)
s=re.split(' +',s)
# print s
# print s0
if (s=="EOF")|(s==s0):
state=False
else:
force=float(s[1])
eee=float(s[0])/100.0
sss=force/area
test_force.append(force)
engineer_strain.append(eee)
while state:
adline()
s=re.sub(';',' ',s)
s=re.split(' +',s)
# print s
# print s0
if (s=="EOF")|(s==s0):
state=False
else:
force=float(s[1])
eee=float(s[0])/100.0
sss=force/area
test_force.append(force)
engineer_strain.append(eee)
engineer_stress.append(sss)
true_strain.append(log(1.0+eee))
true_stress.append(sss*(1.0+eee))
plastic_strain.append(log(1.0+eee)-sss*(1.0+eee)/E_modulus)
f.close()
>>>>>>>>>>>###3 simu_strain=[]
simu_P_strain=[]
simu_triax=[]
simu_force=[]
simu_E=204323.0
simu_little=str(int(little)+3)
simu_name="New_pass"+simu_little+"test.dat"
print 'refer to'+simu_name
simu_f=open(simu_name,'r')
true_strain.append(log(1.0+eee))
true_stress.append(sss*(1.0+eee))
plastic_strain.append(log(1.0+eee)-sss*(1.0+eee)/E_modulus)
f.close()
>>>>>>>>>>>###3 simu_strain=[]
simu_P_strain=[]
simu_triax=[]
simu_force=[]
simu_E=204323.0
simu_little=str(int(little)+3)
simu_name="New_pass"+simu_little+"test.dat"
print 'refer to'+simu_name
simu_f=open(simu_name,'r')
simu_state=True
s0=adlines()
s0=s0[-1]
s0=re.sub(';',' ',s0)
s0=re.split(' +',s0)
# print s0
simu_f.seek(0)
simu_s1=adline()
while simu_state:
simu_s2=adline()
simu_s2=re.sub(';',' ',simu_s2)
simu_s2=re.split(' +',simu_s2)
if (simu_s2=="EOF")|(simu_s2==s0):
simu_state=False
else:
s0=adlines()
s0=s0[-1]
s0=re.sub(';',' ',s0)
s0=re.split(' +',s0)
# print s0
simu_f.seek(0)
simu_s1=adline()
while simu_state:
simu_s2=adline()
simu_s2=re.sub(';',' ',simu_s2)
simu_s2=re.split(' +',simu_s2)
if (simu_s2=="EOF")|(simu_s2==s0):
simu_state=False
else:
# print simu_s2
s_force=float(simu_s2[5])
s_eee=float(simu_s2[2])
s_triax=float(simu_s2[3])
s_sss=s_force/area
simu_force.append(s_force)
simu_triax.append(s_triax)
simu_strain.append(s_eee)
simu_P_strain.append(log(1.0+s_eee)-s_sss*(1.0+s_eee)/simu_E)
simu_f.close()
>>>>>>>>>>>###3
s_force=float(simu_s2[5])
s_eee=float(simu_s2[2])
s_triax=float(simu_s2[3])
s_sss=s_force/area
simu_force.append(s_force)
simu_triax.append(s_triax)
simu_strain.append(s_eee)
simu_P_strain.append(log(1.0+s_eee)-s_sss*(1.0+s_eee)/simu_E)
simu_f.close()
>>>>>>>>>>>###3
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论