ANSA获取所有PART的名称,并输出至文件中。
import ansa
from ansa import base
from ansa import constants
with open("D:/temp/temp.txt", 'w') as f2:
all_part = base.CollectEntities(constants.NASTRAN,None,'ANSAPART')
name_ids = set(map(lambda x: x._name, all_part))
print (name_ids)
f2.write(str(name_ids))
# 打开文件进行读取
with open('example.txt', 'r') as file:
content = file.read()
print(content)
# 逐行读取
with open('example.txt', 'r') as file:
for line in file:
print(line, end='')
# 写入文本到文件
with open('example.txt', 'w') as file:
file.write("Hello, World!\n")
with open('example.txt', 'a') as file:
file.write("Another line.\n")
# 以二进制模式写入
with open('binary.dat', 'wb') as file:
file.write(b'\x00\x01\x02\x03')
# 以二进制模式读取
with open('binary.dat', 'rb') as file:
content = file.read()
print(list(content))
# 打开一个图片文件进行读取
with open("D:/temp/无标题.png", 'rb') as source_file:
content = source_file.read()
# 将读取的内容写入到新的图片文件
with open("D:/temp/无标题1.png", 'wb') as dest_file:
dest_file.write(content)