I just want to write a python program,it can be called in the linux terminal like the command "cd" to change the directory of the shell terminal<div> </div><div><includetail><div><br></div><div><br></div><div style="padding: 2px 0px; font-family: Arial Narrow; font-size: 12px;">------------------ 原始邮件 ------------------</div><div style="background: rgb(239, 239, 239); padding: 8px; font-size: 12px;"><div><b>发件人:</b> "Dave Angel"<d@davea.name>;</div><div><b>发送时间:</b> 2012年6月28日(星期四) 晚上8:12</div><div><b>收件人:</b> "Alex Chen"<wustcsvstudio@vip.qq.com>; <wbr></div><div><b>抄送:</b> "python-list"<python-list@python.org>; <wbr></div><div><b>主题:</b> Re: how can I implement "cd" like shell in Python?</div></div><div><br></div>On 06/28/2012 05:30 AM, 梦幻草 wrote:<br>> how can I implement "cd" like shell in Python?<br>><br><br>import os<br>os.chdir("newdirectory")<br><br><br>But the more important question is why you want to.  Inside a Python<br>program, many people find that changing directory causes unexpected<br>difficulties, and they simply keep track of a full path instead, using<br>various os.path functions to manage it.<br><br>And once the python program ends, the shell should have no knowledge of<br>what you changed it to.<br><br>Now, a particular shell program might have some convention that allows a<br>program to inform it what directory to continue in.  But that's a<br>question about that shell, not about Python.  And you never said what<br>your environment is.<br><br><br>So give some more specifics to your needs, and somebody is likely to<br>know an approach.<br><br><br><br>-- <br><br>DaveA<br><br><br></includetail></div>