2

I understand ! tells iPython to treat the expression as "Bashy", but how do I tell iPython to treat an expression as "Pythony" so I can mix the two together?

For example, if I have a list of folders, how do I cd into them by indexing into the list?

In [57]: x = !find . -type d

In [58]: !cd x[-1]
sh: line 0: cd: x[-1]: No such file or directory

iPython is not making the substitution for x[-1]

1 Answer 1

4
!cd {x[-1]}

If you want change current dir of ipython:

cd {x[-1]}
Sign up to request clarification or add additional context in comments.

2 Comments

What's the functional difference between the first one and second one?
The first one forks a new process, so it won't change the ipython(it's parent)'s current dir.

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.