![](/img/trans.png)
[英]How do I execute a Jupyter notebook from an IPython shell?
[英]How do I pass a string to a boto3 function in IPython from a Jupyter notebook?
我在Jupyter中设置了一个环境,允许用户从AWS Glue查询他们的数据库模式。 Jupyter line magic接受2个参数:数据库名称和表名。
然后使用split()解析这些参数,并将其分为两个参数:database和table。
将这些传递给glue.get_table调用的最佳方法是什么? 哪个接受我之前在代码中明确声明的2个参数?
我对Python很新,可能在这里错过了一个明显的答案,但我现在将它们作为字符串变量传递。
@line_magic('describe')def describe(self,line,local_ns = None):
database = line.split(" ")[0]
view = line.split(" ")[1]
glue = boto3.client('glue', region_name=ec2_metadata.region)
response = glue.get_table(DatabaseName='%s', Name='%s' % (database, view))
我希望看到这些值传递给boto,就像我自己写的那样,但我看到了
TypeError:并非在字符串格式化期间转换所有参数
被抛到glue.get_table()函数上
尝试这个:
response = glue.get_table(DatabaseName=database, Name=view)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.