6

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

2 Answers 2

11

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: enter image description here

Sign up to request clarification or add additional context in comments.

Comments

7

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

3 Comments

thanks. I feared that was the answer. I just learning Python so I will train on intelliJ IDEA. Thanks again Fabio
I tried making the 'age' from an text into an integer by changing the code as follows: dbutils.widgets.int("age", "How old are you?"), \n but Databricks doesn't recognize the 'int'. Is there a way of changing to integer?
I figured it out ... age = int(dbutils.widgets.get("age"))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.