how can I implement "cd" like shell in Python?

Hans Mulder hansmu at xs4all.nl
Thu Jun 28 13:33:10 CEST 2012


On 28/06/12 13:09:14, Sergi Pasoev wrote:
> Do you mean to implement the cd command ? To what extent do you want to
> implement it ? if what you want is just to have a script to change the
> current working directory, it is as easy as this:
> 
> 
> import sys
> import os
> os.chdir(sys.argv[1])
> 
> plus you could add some error-handling code.

'cd' is a shell built-in, because otherwise it would have no effect.

You can write a Python script that invokes os.chdir(), but that won't
have any effect on the shell that starts the script.

What are you trying to achieve?

-- HansM



More information about the Python-list mailing list