Fxs7576
Fxs7576

Reputation: 1341

Executing Python File from A String Directory in Jupyter Notebook

Currently I am running a .py file at Jupyter Notebook using the following command:

!python /Users/manage.py /Users/u.data

Sometimes I have a really long file path. Thus, is there a way that I can execute it with anything similar to this?

path_name = "/Users/"
!python "{}manage.py".format(path_name) "{}u.data.format(path_name)

Upvotes: 1

Views: 829

Answers (1)

cco
cco

Reputation: 6291

The notebook will interpolate variables in magic commands if you prefix the variable name with $

path_name = "/Users/"
py_file = "{}manage.py".format(path_name)
data = "{}u.data".format(path_name)

!python $py_file $data 

Upvotes: 2

Related Questions