-1

I'm trying to change the directory of my terminal from a Python script. The program execute successfully but the directory in my terminal doesn't change. Here is the program.

os

path = "/home/najeeb/Desktop/project/scan"

r = os.getcwd()
print "\n Current working directery is %s \n" % r

os.chdir(path)
retval = os.getcwd()

print "Directery changes successfull %s \n" % retval

screen shot

Morgan Thrapp
  • 9,748
  • 3
  • 46
  • 67
Najeeb Choudhary
  • 396
  • 1
  • 3
  • 21
  • 2
    Each program on the system has its own Current-Working-Directory and child processes cannot change their parent's working directory. In your example, the command-line-shell is one program that invokes `python` in order to execute your script. Your script's scope is limited to that `python` program. – Brian Cain Oct 05 '15 at 14:11

1 Answers1

0

Python can't change what directory your terminal is running in. It can only change the path inside of the script.

Morgan Thrapp
  • 9,748
  • 3
  • 46
  • 67