2

I'm using inspect.getfile() to get the python file directory of some class of interest, and then I would ideally like to be able to open it semi-automatically. As it stands, I copy paste the directory into the open window and it takes some navigating.

Any thoughts?

Thanks!

3
  • You want the file to open in Spyder once you've found the path? Commented Apr 17, 2019 at 15:45
  • 1
    Yeah, I would like some easy way of going from a directory string to opening the file in spyder. Does that seem unreasonable? Commented Apr 17, 2019 at 15:52
  • Not at all - just wanted to be sure before I answered Commented Apr 17, 2019 at 15:55

1 Answer 1

5

Once you have the path to your file, you can use IPython magic command %edit path from the console or within a script in the following way:

from IPython import get_ipython

path = "C:/path/to/your/file.py"

ipython = get_ipython()

ipython.magic(f"%edit {path}")
Sign up to request clarification or add additional context in comments.

1 Comment

(Spyder maintainer here) Pretty clever!! I haven't thought about that.

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.