Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run / execute input cells in Databricks Python Notebook

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

like image 425
Carltonp Avatar asked Aug 27 '26 19:08

Carltonp


2 Answers

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

like image 128
Bob Bricks Avatar answered Aug 31 '26 00:08

Bob Bricks


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

like image 40
Fabio Schultz Avatar answered Aug 30 '26 23:08

Fabio Schultz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!