How to run / execute input cells in Databricks Python Notebook

Viewed 5460

I written the following code in Databricks notebook

name = input("Please enter your name: ")
age = input("How old are you, {0}?".format(name))
print(age)

As you guessed, after running the cell I am asked to 'Please enter your name:' The problem is I don't where to make the entry. If this was written in intelliJ IDEA or IDLE I would be given a separate window to enter my name. However, with Databricks notebook, even if I enter the answer in a different cell it appears to be constantly waiting for an input, see image:

where to enter

I really should know the answer to this

1 Answers

I think what you need is

dbutils.widgets.text("name", "Please enter your name")
dbutils.widgets.text("age", "How old are you?")

Look at the top of your notebook and you will look the textboxes to fill, fill it and execute another cell with this commands

name = dbutils.widgets.get("name")
print(name)
age = dbutils.widgets.get("age")
print(age)

Doc link https://docs.databricks.com/user-guide/notebooks/widgets.html#widget-types

Related