1

我必须使用函数将.las一个目录中的文件转换为文件。.xlsxlas2excelbulk

目前我可以在命令提示符下执行此操作,但我想使用 Python 执行此操作:可能吗?

这是我提到的链接https://lasio.readthedocs.io/en/latest/exporting.html

  • 打开 CMD

  • 使用“ cd 切换到具有 las 文件的文件夹

  • las2excelbulk -r -i

该文件将被转换。

# this is working for only one file

import lasio

las = lasio.read('*.las')

las.to_excel('testsamplelas.xlsx')
4

1 回答 1

2

to 的参数lasio.read()只能是单个文件名,但您可以使用 Python 标准库中的osfnmatch模块递归地遍历所有 .las 文件。

import fnmatch
import os
import lasio

for root, dirnames, filenames in os.walk("your_directory"):
    for filename in fnmatch.filter(filenames, '*.las'):
        path = os.path.join(root, filename)
        las = lasio.read(path, ignore_header_errors=True)
        las.to_excel(path + ".xlsx")

lasio.read(..., ignore_header_errors=True)相当于las2excelbulk -i

检查命令行工具背后的代码以获取更多信息也可能很有用。las2excelbulk

于 2019-02-09T03:10:27.087 回答