0

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
5
  • Provide an minimal reproducible example in your question Commented Dec 20, 2018 at 0:31
  • Not sure how I could do that in this instance ... the script exists. I'll add that. Commented Dec 20, 2018 at 0:34
  • Replace your complex remap-discourse-users-to-worldpress.py script by something perhaps as simpls as hello-world.py script Commented Dec 20, 2018 at 0:36
  • To run a program (perhaps another Python script) from Python, consider subprocess Commented Dec 20, 2018 at 0:38
  • I was looking for a way to stop quitting and opening iPython each time I made a change to the classes I'm working on. reload not was working well for me. Commented Dec 20, 2018 at 0:40

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.