ANSA获取所有PART的名称,并输出至文件中。
import ansafrom ansa import basefrom ansa import constantswith 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)