I'm somehow unable to change the current working directory in IPython and I have no idea why.
In the example below I start IPython from the root of the C drive and try to change the current working directory in several ways. Weird things result:
C:\>ipython
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 2.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: cd
C:\Users\jkokorian
In [2]: %cd "C:\Dell"
C:\Dell
In [3]: cd
C:\Users\jkokorian
In [4]: import os
In [5]: os.chdir("C:\Dell")
In [6]: os.getcwd()
Out[6]: 'C:\\Dell'
In [7]: cd
C:\Users\jkokorian
In [8]: os.getcwd()
Out[8]: 'C:\\Users\\jkokorian'
Somehow the working directory always defaults to my home folder, even when IPython is started from the root of C:.
Does someone have a clue what's going on here?
After some experimenting I figured out that the 'cd' magic command without any arguments resets the current working directory to 'C:\Users\jkokorian'. I assumed that it would echo the current working directory, but apparently it doesn't.
If you wish to run certain .py file under certain directory which differs from the current directory. You need execute the following 2 rows together:
%cd C:\example_folder1\example_folder2\
%run example.py
mind that the last \
can make sure it returns to next row instead of execute the current row.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With