Snakemake Shell命令中通过Shell变量访问Python字典值触发NameError的问题求助
Snakemake Shell命令中通过Shell变量访问Python字典值触发NameError的问题求助
各位好,我最近在写Snakemake规则的时候碰到了个棘手的问题:我尝试在shell命令里用Shell变量去访问Python字典的值,但运行时直接触发了NameError错误。
先给大家看一下我简化后的测试代码:
my_dict = {"SHELL_KEY": "key3"} rule another_rule: output: "output.txt" shell: """ x='SHELL_KEY' echo {my_dict[$x]} > {output} """
运行之后抛出的错误信息是这样的:
RuleException in rule another_rule in file /home/zhujack/workflow/ngs_aPipe_snake_dev/rules/align.rules, line 43: NameError: The name '$x' is unknown in this context. \ Please make sure that you defined that variable. \ Also note that braces not used for variable access have \ to be escaped by repeating them, i.e. {{print $1}}, \ when formatting the following: x='SHELL_KEY' echo {my_dict[$x]} > {output}
错误提示说$x这个名字在当前上下文里不存在,但我明明在shell代码里定义了这个变量啊。有没有大佬能帮我分析下问题出在哪,应该怎么调整才能实现我想要的效果?
备注:内容来源于stack exchange,提问作者Jack Z
相关产品推荐
相关产品推荐

