python - Read values from another cell in IPython Notebook and supply them for "input()" -


as example, if have cell looks like:

in [*]: in range(int(input())):             print(i**2) 

when cell run, input box pops , waits input provided. there built-in magic command or way programmatically supply values when input() encountered?

i write answer, although more or less comment.

one "hacky" way overwrite input or make generator returns input-function constant return value. kind of mocking it…

def input_generator(return_value):     def input():         return return_value     return input 

this work as:

>> input = input_generator(42) >> input() 42 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -