Actually need to go some path and execute some command and below is the code code:
presently i am in
Actually whats happening here is when i first used
but for the second one i need to run a file by moving to one folder back that is
So can anyone let me how to move one folder back in python asked Sep 5, 2012 at 11:10
2 Just like you would in the shell.
answered Sep 5, 2012 at 11:13
0 Here is a very platform independent way to do it.
Then you have the path, and you can chdir or whatever with it. answered Jul 18, 2013 at 14:51
chimpsarehungrychimpsarehungry 1,6152 gold badges17 silver badges28 bronze badges 2 Just call
the same as in any other language :) answered Sep 5, 2012 at 11:13
moopetmoopet 5,8841 gold badge30 silver badges35 bronze badges 1
Exact answer for your question is os.chdir('../')Use case:
To navigate to then, put it in answered May 11, 2019 at 18:30
think about using absolute paths
answered Sep 5, 2012 at 11:20
My problem was fixed with this command first answered Nov 7, 2019 at 17:46
The answers mentioned above are correct. The following is more a It usually happens when your Python script is in a nested directory and you want to go one level up from the current working directory to maybe let's say load a file. The idea is to simply reformat the path string and prefix it with a '../'. So an example would be.
This format is similar to when used in a terminal. Whenever in doubt fire up a terminal and experiment with some commands. The format is reflected in the programming language. answered May 11, 2020 at 7:27
Define this function in your script and call it whenever you want to go back just by one folder:
answered Feb 11 at 12:54
|