NameError:BigQueryML教程中未定义名称“uuid”

2024-05-23 22:04:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我开始学习BigQueryML,并试图完成this tutorial。我遇到的问题是,当我尝试添加这行代码时(在步骤一第15部分中找到):

dataset_id = "bqml_tutorial_{}".format(str(uuid.uuid4().hex))

我得到了错误

NameErrorTraceback (most recent call last)
<ipython-input-9-1746232870d0> in <module>()
      3 # other invocations of this tutorial.  In practice, you could leverage
      4 # a persistent dataset and not create/destroy it with each invocation.
----> 5 dataset_id = "bqml_tutorial_{}".format(str(uuid.uuid4().hex))

NameError: name 'uuid' is not defined

我试过使用from uuid import UUID,但运气不好

谢谢你的帮助


Tags: 代码idformatuuid错误not步骤this
1条回答
网友
1楼 · 发布于 2024-05-23 22:04:51

您专门导入了UUID,这是一个可以实例化的特定类,但不是uuid4函数:https://docs.python.org/3/library/uuid.html#uuid.UUID

如果要使用^{},必须实际导入它,因为它与UUID类是分开的:

from uuid import uuid4
print(uuid4())
# output: 0e18abd8-8470-48ef-be58-6bc34eea7548

这个问题本可以通过查看官方文档来避免。在进行故障排除时,这始终是一个很好的起点

相关问题 更多 >