Chuyển đến nội dung chính
ATK Pine Script®

Import Library

Cách khai báo, publish và import library PyneScript sử dụng library_import và import_library.

Import Library#

library_import(name, version=None, exports=None, alias=None)#

Phân giải một library PyneScript ATK đã publish, xác thực các export, ghi metadata vào script context và trả về đối tượng namespace chứa các callable đã chọn.

import_library(spec, exports=None, alias=None)#

Wrapper tiện lợi trên library_import. Sử dụng khi spec library đã mã hóa sẵn tên và thông tin version bạn muốn.

Lưu ý hành vi: import library nhận biết version, các callable được export được phát hiện từ module đích, export bị thiếu sẽ gây lỗi, và một library không thể import chính nó.

Phạm vi hiện tại: library đã publish có thể export các callable và kiểu enum. Import chọn lọc như Pyne Enum Utils@1::TrendMode,resolve_length được hỗ trợ trong các file Python thuần thông qua import_library(...). Cú pháp import dạng chuỗi cũng được hỗ trợ, nhưng chỉ sau khi editor tiền xử lý mã nguồn thành Python hợp lệ.

Mẫu khai báo và import library#

from source import library, import_library

library("Pyne Utils", version=2, overlay=False)

def plus_one(value):
    return int(value) + 1


# In another script
utils = import_library("Pyne Utils@2", exports=["plus_one"])
result = utils.plus_one(41)