我正在使用一个Python包来读取某些类型的数据。它从数据中创建属性,以便轻松访问与数据相关的元信息
如何为属性创建短名称
基本上,我们假设包名是read_data
,它有一个名为data_header_infomation_x_location
的属性
import read_data
my_data = read_data(file_path)
如何为该属性创建一个短名称
x = "data_header_infomation_x_location"
my_data[1].x
给出错误无属性
以下是我的案例的完整示例
from obspy.io.segy.core import _read_segy
file_path = "some_file_in_my_pc)
sgy = _read_segy(file_path, unpack_trace_headers=True)
sgy[1].stats.segy.trace_header.x_coordinate_of_ensemble_position_of_this_trace
最后一行给出了一个数字。e、 g.,x位置
我想要的是用一个短名称重命名所有这些长嵌套属性stats.segy.trace_header.x_coordinate_of_ensemble_position_of_this_trace
举个例子
attribute = "stats.segy.trace_header.x_coordinate_of_ensemble_position_of_this_trace"
getattr(sgy[1], attribute )
不起作用
怎么样:
您不能一次性请求属性的属性,但这会在层之间循环以获得您要查找的最终值
相关问题 更多 >
编程相关推荐