从Glue脚本访问作业参数

0

【以下的问题经过翻译处理】 我定义了一个接受参数的Glue任务,但找不到如何访问这些参数的示例?

profile picture
ESPECIALISTA
feita há 6 meses2 visualizações
1 Resposta
0

【以下的回答经过翻译处理】 你可以像使用常规的Python sys.argv参数一样读取参数。

import sys
print "This is the name of the script: ", sys.argv[0]
print "Number of arguments: ", len(sys.argv)
print "The arguments are: " , str(sys.argv)

或者,你可以使用Glue的getResolvedOptions按名称读取参数。在这种情况下,你需要在参数名前加上“--”例如 --Arg1 Value1

from awsglue.utils import getResolvedOptions
args = getResolvedOptions(sys.argv, ['TempDir','JOB_NAME', 'Arg1'])
print "The args are:",str(args)
print "The value is:",args['Arg1']
profile picture
ESPECIALISTA
respondido há 6 meses

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas