One way to enable user input for file paths in a Jupyter Notebook without allowing code edits is to use the widgets
module.
First, import the widgets
module:
from ipywidgets import widgets
Next, create a text box widget for the user to input the file path:
file_path = widgets.Text(
value='',
placeholder='Enter a file path',
description='File path:',
disabled=False
)
display(file_path)
The value
parameter sets the initial value of the text box, the placeholder
parameter provides a hint to the user on what to enter, and the description
parameter adds a label to the widget.
Finally, use the value
attribute of the file_path
widget to access the user input in your code:
with open(file_path.value, 'r') as f:
# do something with the file
This allows the user to input the file path without having to edit the code, and the widgets module takes care of all the user input handling.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-12-10 11:00:00 +0000
Seen: 9 times
Last updated: Jun 29 '21
How can user input be added to an array using a loop in C# and then displayed through printing?
If the chips occupy 80% of the space, what is the best way to package the remaining input?
What is the process for posting input values to a database?
What is the solution for aligning input vertically in different rows with Bootstrap 5?
How can user input be added to an empty nested array using useState?
How to provide Arduino input parameters of any size without creating a struct?
How do I use C# Regex to ensure that a string has one dot followed by numbers?