简体   繁体   English

如何从Jupyter笔记本中将字符串传递给IPython中的boto3函数?

[英]How do I pass a string to a boto3 function in IPython from a Jupyter notebook?

I am setting up an environment in Jupyter that allows a user to query their Database Schema from AWS Glue. 我在Jupyter中设置了一个环境,允许用户从AWS Glue查询他们的数据库模式。 The Jupyter line magic accepts 2 arguments: the database name, and the table name. Jupyter line magic接受2个参数:数据库名称和表名。

These arguments are then parsed with split(), and separated into two arguments: database, and table. 然后使用split()解析这些参数,并将其分为两个参数:database和table。

What would be the best way to pass these to the glue.get_table call? 将这些传递给glue.get_table调用的最佳方法是什么? Which accepts 2 argument which I was previously explicitly declaring in the code? 哪个接受我之前在代码中明确声明的2个参数?

I'm fairly new to Python and may be missing an obvious answer here, but I'm currently passing them as string variables. 我对Python很新,可能在这里错过了一个明显的答案,但我现在将它们作为字符串变量传递。

@line_magic('describe') def describe(self, line, local_ns = None): @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))

I am expecting to see these values passed into boto as if I were to write them in myself, but I am seeing 我希望看到这些值传递给boto,就像我自己写的那样,但我看到了

TypeError: not all arguments converted during string formatting TypeError:并非在字符串格式化期间转换所有参数

being thrown on the glue.get_table() function 被抛到glue.get_table()函数上

尝试这个:

response = glue.get_table(DatabaseName=database, Name=view)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 IPython shell 执行 Jupyter notebook? - How do I execute a Jupyter notebook from an IPython shell? 如何修复 Jupyter notebook 依赖项? ModuleNotFoundError:没有名为“boto3”的模块 - How to fix Jupyter notebook dependancies? ModuleNotFoundError: No module named 'boto3' 如何设置ipython jupyter笔记本的单元格? - How do I cron an ipython jupyter notebook's cells? 如何在 IPython (Jupyter) Notebook 的远程机器上添加 kernel? - How do I add a kernel on a remote machine in IPython (Jupyter) Notebook? 如何获取当前的 IPython / Jupyter Notebook 名称 - How do I get the current IPython / Jupyter Notebook name Boto3 无法在 jupyter 笔记本中加载,但无法在 python shell 中加载 - Boto3 fails to load in jupyter notebook but not in python shell 如何在不使用ipython的情况下配置jupyter笔记本以使用某些导入来预加载单元格? - How do I configure jupyter notebook for having a pre loaded cell with certain imports without using ipython? 如何在浏览器中增加 Jupyter/ipython 笔记本的单元格宽度? - How do I increase the cell width of the Jupyter/ipython notebook in my browser? 在 Jupyter Notebook 中使用 ipython-sql 时,如何创建自定义 Sqlite UDF? - How do I create a custom Sqlite UDF while using ipython-sql in a Jupyter Notebook? 如何在 Jupyter notebook (iPython) 中并排显示 2 张图像? - How do I make 2 images appear side by side in Jupyter notebook (iPython)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM