Skip to content

How to get a resource by name #8421

Answered by yuhan
dagsir[bot] bot asked this question in Q&A
Discussion options

You must be logged in to vote

You can use getattr, for example:

from dagster import op, job, ResourceDefinition


@op(required_resource_keys={"a", "b", "c"})
def my_op(context):
    print(getattr(context.resources, "a"))  # 1
    print(getattr(context.resources, "b"))  # 2
    print(getattr(context.resources, "c"))  # 3


@job(
    resource_defs={
        "a": ResourceDefinition.hardcoded_resource(1),
        "b": ResourceDefinition.hardcoded_resource(2),
        "c": ResourceDefinition.hardcoded_resource(3),
    }
)
def my_job():
    my_op()

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by yuhan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant