How do go into a directory without being given its full path in python 2?
<p>I am currently trying to go into a folder and call a python 2 script, but I cannot get any answer to go into a folder without using its full path. As example in DOS I would normally type this:</p>

<pre><code>C:\unknownpath\&gt; cd otherpath
C:\unknownpath\otherpath\&gt;
</code></pre>

<p>Thanks for any help.</p>

<p>Try this:</p>

<pre><code>import os
os.chdir('otherpath')
</code></pre>

<p>This at least matches your DOS example, and will change your working directory to <code>otherpath</code> relative to the directory the command is run from. For example if you are in <code>/home/myusername/</code>, then this will take you to <code>/home/myusername/otherpath/</code>. You can also use <code>.</code> for the current directory or <code>..</code> to move back one directory. So if you are in <code>/home/myusername/Desktop/</code>, <code>os.chdir('..')</code> would change the working directory to <code>/home/myusername/</code> and <code>os.chdir('../Documents/</code> would change you to <code>/home/myusername/Documents/</code>, etc.</p>

<p>Forgive my use of Unix-style paths, but you should be able to easily translate these commands to Windows paths if that is the platform you are on. I don't want to attempt to use Windows paths in my examples because I won't be able to test their efficacy.  </p>

python