Keith John Hutchison
Keith John Hutchison

Reputation: 5277

How to run a script file from ipython

How do you run a script from iPython?

I am looking for a way to stop quitting and opening iPython each time I made a change to the classes I'm working on. reload is not working well for me.

The contents of the script ./hello-world.py I'm trying to run from iPython is

#!/usr/bin/env python

print('hello world')

I've tried

hello-world.py                                                                                                                                
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-136f991ec00e> in <module>
----> 1 remap-discourse-users-to-wordpress.py

NameError: name 'hello' is not defined

and

 ./hello-world.py                                                                                                                              
  File "<ipython-input-7-6d10642b89fe>", line 1
    ./remap-discourse-users-to-wordpress.py
    ^
SyntaxError: invalid syntax

Upvotes: 0

Views: 159

Answers (1)

Keith John Hutchison
Keith John Hutchison

Reputation: 5277

I discovered all you have to add is run.

In [8]: run ./hello-world.py                                                                                                                          
hello-world

this has increased my productivity by being able to reload the models I'm working without having to rerun all the intervening steps to get back to the state I was at.

Upvotes: 1

Related Questions