我是 Python 新手。我正在模拟氧化锆纳米管。已经在 PDB 中生成了结构,想将文件导出到 ANSYS。下面的代码是为 Python 编写的:
node_value = 0
file = open('C:\\xyz\\test.pdb', 'r')
igot = file.readlines()
output_file = open('C:\\xyz\\nodes.txt', "a") # needs input for distinct file
utput_file.write('/PREP7'+"\n") #open pre-processing menu
for line in igot:
if line.find("ATOM") > -1:
node_value = node_value + 1
nv = str(node_value)
xyz = line.split()
#print kv,",", xyz[6], ",", xyz[7], ",", xyz[8]
line_i = "N" + ', '+ nv + ', ' + xyz[6] + ', ' + xyz[7] +', '+ xyz[8]+ "\n"
print (line_i)
output_file.write(line_i)
我收到一条错误消息:File "c:\xyz\test.py", line 2, in file = open('C:\xyz\test.pdb', 'r')
builtins.FileNotFoundError:[Errno 2] 没有这样的文件或目录:'C:\xyz\test.pdb'
我该如何解决这个问题?