0

When the function below is entered into a notebook cell, the output will have an input box to enter the details of the prompt.

def a():
    val = raw_input("abc")
    print "Entered value: %s" % val

enter image description here

I'm trying to achieve the same thing by running the script, but it doesn't work. I've copied the same code for the function above into a script sample.py as below.

# cat sample.py
def a():
    val = raw_input("abc")
    print "Entered value: %s" % val

a()

Attempts to achieve the same behavior of getting a notebook prompt while running the script from notebook:

1. Using the '!' prefix

This command just keeps running without giving any prompt:

[*] !python sample.py
abc

2. Using %%bash

Gives the following error:

%%bash
python sample.py
EOFError: EOF when reading a line

What is the reason for this to fail and is there a workaround to get it working as expected?

Shyam Sunder
  • 1,200
  • 2
  • 11
  • 23

1 Answers1

0

The two command you've used are used for shell command and bash script respectively.

To run Python script as a program you can use Magic command run.

Krishna
  • 6,107
  • 2
  • 40
  • 43