#遇到问题的现象描述
任务是写segy数据到指定目录。segyio.create(output_file, spec)中的两个参数都已经定义,在调用前也进行了检查,运行打印结果应该是正确的,大家后面可以看到。当程序执行到self.file_write_thread = FileWriteThread(self.output_file,self.spec)这一行时报错,提示缺少spec。希望有人能够找出错误原因并给出修改代码,谢谢!提醒一定不要寄希望于chatgpt4o,它找不出来错误。
#问题相关代码片,运行结果,报错内容
相关代码:
class MainWindow(QWidget):
def __init__(self):
super().__init__()
# Thread control
self.file_write_thread = None
self.spec = None # 初始化 self.spec,确保它是一个实例属性(修改行)
self.output_file = None # 初始化 self.output_file,以确保它是一个实例属性(新增行)
def on_save_button_clicked(self):
print("Save button clicked") # Debug statement
...
filename, _ = QFileDialog.getOpenFileName(self, "Open SEGY File", "", "SEGY Files (*.sgy *.segy)")
result = read_segy_text(filename)
if len(result) == 10:
num_samples, text_content, trace, tracecount, interval, dataformat, ilines, xlines, num_lines, num_traces = result
print("构建spec")
self.spec = segyio.spec() # 将创建的 spec 赋值给 self.spec(修改行)
print("spec类型",type(self.spec))
self.spec.samples = np.repeat(num_samples, num_lines * num_traces) #
self.spec.format = dataformat #已经修改为常量或枚举
self.spec.tracecount = num_lines * num_traces # 确保 tracecount 是整数
self.spec.interval = interval
self.spec.ilines = ilines
self.spec.xlines = xlines
print("打印调试")
print("spec类型",type(self.spec))
print(self.spec.samples)
print(self.spec.tracecount)
print(self.spec.interval)
print(self.spec.format)
print(self.spec.ilines)
print(self.spec.xlines)
print("打印完毕")
# Create FileWriteThread instance
self.output_file = 'D:/Project/test88/output.sgy' # 确保 output_file 被初始化(修改行)
self.file_write_thread = FileWriteThread(self.output_file,self.spec)
运行结果:
打印调试
[751 751 751 ... 751 751 751]
9911
4000
1
[1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070]
(备注:太多这里省略了)
打印完毕
打印self.spec,确认是否none: <segyio.segy.spec object at 0x00000208225671F0>
错误信息:
Traceback (most recent call last):
File "D:\ML\mldata\plot_project\deeplearning\segy_loading2.py", line 224, in on_save_button_clicked
self.file_write_thread = FileWriteThread(self.output_file, self.spec) # 确保 self.spec 被传递
TypeError: FileWriteThread.init() missing 1 required positional argument: 'spec'
#我的初步解答思路是
目前没有找到。
#操作环境、软件版本等相关信息
win11, python 3.10, segyio 1.9.12