Reputation: 1344
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:
I really should know the answer to this
Upvotes: 6
Views: 11702
Reputation: 111
The input
function is now natively supported in Databricks for DBR 11.2+.
An example notebook showing the use of input
with pdb
is available here:
https://docs.databricks.com/_static/notebooks/python-debugger.html
A short screencast showing the execution of your example:
Upvotes: 11
Reputation: 527
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
Upvotes: 7